Focus on New Windows with Selenium IDE

Debomita Bhattacharjee
Updated on 28-Nov-2020 13:49:53

720 Views

We can focus on new windows with Selenium IDE. On clicking a link, a new tab or a window opens. After accessing the new window, we can close it and shift to the parent window.Click on a link with the below step. Visit site is the name of the link to be clicked.Select the window which opened on clicking the link.Add Event is the page title of the window opened on clicking the link. Now, we can perform actions on the new window.Close the new window with the below step.Step back to the parent window with the below step. The ... Read More

Best Practice to Wait for a Change with Selenium WebDriver

Debomita Bhattacharjee
Updated on 28-Nov-2020 13:48:19

4K+ Views

The best practice to wait for a change in Selenium is to use the synchronization concept. The implicit and explicit waits can be used to handle a wait. The implicit is a global wait applied to every element on the page.The default value of implicit wait is 0. Also it is a dynamic wait, meaning if there is an implicit wait of 5 seconds and the element becomes available at the 3rd second, then the next step is executed immediately without waiting for the entire 5 seconds. Once the 5 seconds have elapsed, and if element is not found, a ... Read More

Deal with Modal Dialog Using Selenium WebDriver

Debomita Bhattacharjee
Updated on 28-Nov-2020 13:46:45

4K+ Views

We can deal with modal dialog boxes with Selenium. A modal is just like a window that enforces the user to access it prior to going back to the actual page. It can be an authentication window as well.Let us work with the below modal dialog −Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; public class ModDialog{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       driver.get("http://www.uitestpractice.com/Students/Switchto");       // identify element and click       WebElement m = driver       .findElement(By.xpath("//button[contains(text(), ... Read More

Remove Default Text from Input Element with Selenium

Debomita Bhattacharjee
Updated on 28-Nov-2020 13:45:20

725 Views

We can consistently remove the default text from an input element with Selenium. The clear method is used to remove the values currently present in an edit box or a text area.The Keys.chord method along with sendKeys can also be used. The Keys.chord method allows you to pass more than one key at once. The group of keys or strings are passed as arguments to the method.First of all, pass Keys.CONTROL and a as arguments to the Keys.chord method. The whole string is then passed as an argument to the sendKeys method. Last, we have to pass Keys.DELETE to the ... Read More

Close Pop-Up Window in Selenium

Debomita Bhattacharjee
Updated on 28-Nov-2020 13:42:57

8K+ Views

We can close the pop up window with Selenium. The getWindowHandles and getWindowHandle methods are used for the pop up window. To store all the window handles opened in a Set data structure, the getWindowHandles method is used.To store the window handle of the pop up in focus, the getWindowHandle method is used. To iterate over the window handles, the iterator method is used. By default, the Selenium driver has the control over the parent window.To switch the focus of the driver to the child pop up window, we can take the help of the switchTo().window method. The window handle ... Read More

Check Scroll Position Using Selenium

Debomita Bhattacharjee
Updated on 28-Nov-2020 13:41:25

4K+ Views

We can check scroll position using Selenium. To check the position we shall use the Javascript executor. We have to verify the value of the window.pageYOffset in the browser.While the URL is launched, the scroll is at the top the value of window.pageYOffset is 0. As we scroll to an element, the value of the window.pageYOffset shall be greater than 0.SyntaxJavascriptExecutor j = (JavascriptExecutor) driver; Long v = (Long) j.executeScript("return window.pageYOffset;");Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.JavascriptExecutor; public class ScrollPosition{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver",       "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); ... Read More

Launch Chrome Browser via Selenium

Debomita Bhattacharjee
Updated on 28-Nov-2020 13:40:16

18K+ Views

We can launch Chrome browser via Selenium. Java JDK, Eclipse and Selenium webdriver should be installed in the system before Chrome browser is launch.Follow the steps one by one to launch Chrome −Navigate to the link: https://chromedriver.chromium.org/downloads.Select the Chrome driver link which matches with the Chrome browser in our system.Next, we have to choose and click on the Chrome driver link which is compatible with the operating system we are using.A zip file gets downloaded. Extract and save the chromedriver.exe file in a location.We can configure the chromedriver.exe file in the following ways −By setting the System Properties in the ... Read More

Get Selenium to Recognize Page Load

Debomita Bhattacharjee
Updated on 28-Nov-2020 13:38:25

10K+ Views

We can get Selenium to recognize that a page is loaded. We can set the implicit wait for this purpose. It shall make the driver to wait for a specific amount of time for an element to be available after page loaded.Syntaxdriver.manage().timeouts().implicitlyWait();After the page is loaded, we can also invoke Javascript method document.readyState and wait till complete is returned.SyntaxJavascriptExecutor js = (JavascriptExecutor)driver; js.executeScript("return document.readyState").toString().equals("complete");After this, verify if the URL matches the one we are looking for.ExampleCode Implementation with implicit wait.import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class Pageload{    public static void main(String[] args) {   ... Read More

Verify Specific Text in Selenium IDE Attribute

Debomita Bhattacharjee
Updated on 28-Nov-2020 13:36:20

2K+ Views

We can verify specific text exists with an attribute in Selenium IDE. This can be done using the assert and verify commands −assert element present − Verifies if the element exists on the page. If assertion fails, the test terminates. It has the element locator as an argument.For example −assert element not present − Verifies if the element does not exist on the page. If assertion fails, the test terminates. It has the element locator as an argument.verify element present − Verifies if the element exists on the page. It has the element locator as an argument.verify element not present ... Read More

Select Value from a Drop-Down Using Selenium IDE

Debomita Bhattacharjee
Updated on 28-Nov-2020 13:34:37

3K+ Views

We can select value from a dropdown using Selenium IDE. The select command is used for this purpose. First of all, Selenium IDE add-on should be installed in Firefox.Launch Firefox and select the Tools menu. Then choose Selenium IDE.Selenium IDE window shall open. Choose the first row inside the test script edit box.Enter select in Command field. To identify the dropdown with the id locator, enter the Target field. The value/index of the option to be selected is to be entered inside the Value field.Once done, click on the Run option.

Advertisements