Found 719 Articles for Testing Tools

Selenium WebDriver StaleElementReferenceException.

Debomita Bhattacharjee
Updated on 26-Oct-2020 07:01:51

672 Views

We have StaleElementReferenceException in Selenium webdriver. As the name suggests, the word stale refers to something which is not new and perished. There may be a scenario in which an element which was present in DOM previously is now no longer available due to modification in DOM.In such a condition, if we try to access that element then StaleElementReferenceException is thrown. This type of exception is encountered due to the below reasons −The element is not present in the DOM any more.The element has been removed totally.There are certain ways we can prevent a StaleElementReferenceException as described below −We can ... Read More

Selenium WebDriver and DropDown Boxes.

Debomita Bhattacharjee
Updated on 26-Oct-2020 06:59:59

431 Views

We can handle dropdown with Selenium webdriver. The static dropdown in Selenium is handled with the Select class and the dropdown should be identified in the html code with the tag.Let us see the html code of a static dropdown.We have to add the import org.openqa.selenium.support.ui.Select statement in the code to work with the methods available in the Select class. The methods to select an option from the dropdown are listed below −selectByValue(val) – The option is selected whose value attribute matches with the argument passed to the method. This method can be used only if the dropdown option has ... Read More

Selenium and iframe in html.

Debomita Bhattacharjee
Updated on 26-Oct-2020 06:58:02

395 Views

We can work with iframe in Selenium webdriver. A frame is defined with , or tag in html code. A frame is used to embed an HTML document within another HTML document.Selenium by default has access to the parent browser driver. In order to access a frame element, the driver focus has to shift from the main browser window to the frame. There are more than one methods to shift to frames −switchTo().frame(id) - The id or name of frame is passed as an argument.Syntax − driver.switchTo().frame("id"), switching to the frame with id.switchTo().frame(m) - The index of frame ... Read More

How to locate element by partial id match in Selenium?

Debomita Bhattacharjee
Updated on 26-Oct-2020 06:56:06

8K+ Views

We can locate elements by partial id match with Selenium webdriver. This can be achieved while we identify elements with the help of xpath or css locator. With the css and xpath expression, we use the regular expression to match id partially.Let us have a look at the id of an element in its html code. The id attribute value is gsc-i-id1.With the css expression, we can use the * and perform a partial match with the id.The css value shall be input[id*='id']. This means the subtext id is present in the actual text gsc-i-id1. We can also use the ... Read More

Refreshing web page by WebDriver when waiting for specific condition.

Debomita Bhattacharjee
Updated on 26-Oct-2020 06:50:34

818 Views

We can refresh a web page by Selenium webdriver when waiting for a specific condition. We can take the help of the driver.navigate().refresh() method to refresh the webpage.ExampleCode Implementation with refresh().import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class BrowserRefresh{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       driver.get("https://www.tutorialspoint.com/index.htm");       // refresh webpage with refresh method       driver.navigate().refresh();    } }We can refresh a webpage with the help of sendKeys method and then send Keys.F5 as an argument to the method. The sendKeys method is ... Read More

How to close the whole browser window by keeping the webDriver active?

Debomita Bhattacharjee
Updated on 26-Oct-2020 06:47:27

646 Views

We can close the whole browser by keeping the webdriver active with the help of Selenium webdriver. To achieve this we have to use the close method. If there are multiple browsers open the close method shall only close the browser which is in focus but the webdriver session still remains alive.There is another method called quit. It closes all the opened browsers and terminates the browser session. At the end of the test execution, it is always a good practice to use the quit method to terminate the session properly and avoid memory leaks.If there is only one browser ... Read More

How to get the content of href within some targeted class using selenium?

Debomita Bhattacharjee
Updated on 26-Oct-2020 06:45:11

745 Views

We can get the content of href within some targeted class with Selenium webdriver. First of all we have to locate the element with an anchor tag having a specific class attribute value with the help of locators like xpath, css or classname.Then we have to take the help of getAttribute method and pass href as an argument to the method. Let us have a look at the html code of an element with an anchor tag having the class and href attribute. The href value of the element should be /account/register?hl=en.ExampleCode Implementation.import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; ... Read More

How to scroll a specific DIV using Selenium WebDriver with Java?

Debomita Bhattacharjee
Updated on 26-Oct-2020 06:43:16

5K+ Views

We can scroll a specific DIV using Selenium webdriver. Selenium cannot handle scrolling directly. It takes the help of the Javascript Executor to do scrolling action to a specific DIV.First of all we have to identify the specific DIV up to which we have to scroll to with the help of xpath or css locator. Next we shall take the help of the Javascript Executor to run the Javascript commands. The method executeScript is used to execute Javascript commands in Selenium. We have to use the scrollIntoView method in Javascript and pass true as an argument to the method.SyntaxWebElement m=driver.findElement(By.xpath("//div[@class='slick-track']")); ... Read More

How to close child browser window in Selenium WebDriver using Java?

Debomita Bhattacharjee
Updated on 26-Oct-2020 06:40:34

5K+ Views

We can close the child browser window in Selenium webdriver. The getWindowHandles and getWindowHandle methods can be used to handle child windows. The getWindowHandles method is used to store all the opened window handles in the Set data structure.The getWindowHandle method is used to store the browser window currently active. To iterate over the window handles, the iterator method is used. We have to add import java.util.Set to accommodate Set and import java.util.List and import java.util.Iterator statements to accommodate iterator in our code.By default, the driver object can access the elements of the parent window. In order to switch its focus ... Read More

How to set Selenium Python WebDriver default timeout?

Debomita Bhattacharjee
Updated on 26-Oct-2020 06:38:44

6K+ Views

We can set default timeout with Selenium webdriver. The method set_page_load_timeout is used to have a timeout for the page loading. The wait time in seconds is passed as parameter to the method.Syntaxdriver.set_page_load_timeout(5)A TimeoutException is thrown if the page is still not loaded after the wait time is passed.We can use the implicit wait concept in synchronization to define the default timeout time. This is a global wait time and applied to every element in the page. The method implicitly_wait is used to define implicit wait. The wait time in seconds is passed as parameter to the method.Syntaxdriver.implicitly_wait(5);A TimeoutException is ... Read More

Advertisements