Found 190 Articles for Selenium Web Driver

How to do drag and drop action in Selenium?

Debomita Bhattacharjee
Updated on 11-Jun-2020 11:41:44

3K+ Views

We can perform drag and drop action in Selenium with the help of Actions class. In order to perform the drag and drop movement we will use dragAndDrop (source, target) method. Finally use build().perform() to execute all the steps.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.interactions.Action; import org.openqa.selenium.interactions.Actions; import java.util.concurrent.TimeUnit; public class DrgAndDrp{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String url = " https://jqueryui.com/draggable/v";       driver.get(url);       driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);       driver.switchTo().frame(0);       WebElement ... Read More

How to perform double click on an element in Selenium?

Debomita Bhattacharjee
Updated on 11-Jun-2020 11:39:56

4K+ Views

We can perform double click on elements in Selenium with the help of Actions class. In order to perform the double click action we will use moveToElement() method, then use doubleClick() method. Finally use build().perform() to execute all the steps.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.interactions.Action; import org.openqa.selenium.interactions.Actions; import java.util.concurrent.TimeUnit; public class DoubleClick{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver",       "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String url = "https://www.tutorialspoint.com/questions/index.php";       driver.get(url);       driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);       ... Read More

How to enter a letter in uppercase in the edit box using Actions in Selenium?

Debomita Bhattacharjee
Updated on 11-Jun-2020 11:36:53

2K+ Views

We can enter a letter in upper case in the edit box in Selenium with the help of Actions. In order to achieve this, we need to first move to the edit box, then click() on that field. Then press SHIFT and enter the letters using sendKeys() method. Finally use build().perform() to execute all the steps.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.interactions.Action; import org.openqa.selenium.interactions.Actions; import java.util.concurrent.TimeUnit; public class UpperCase{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String url = ... Read More

How to perform right click on an element with Actions in Selenium?

Debomita Bhattacharjee
Updated on 10-Jun-2020 15:05:47

2K+ Views

We can perform right click on an element in Selenium with the help of Actions. In order to perform the right click action we will use contextClick () method. First we need to move to the specific element with the help of moveToElement() method then will do the right click with contextClick() method. Finally use build().perform() to execute all the steps.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.interactions.Action; import org.openqa.selenium.interactions.Actions; import java.util.concurrent.TimeUnit; public class RightClick{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();   ... Read More

How to perform mouseover action on an element in Selenium?

Debomita Bhattacharjee
Updated on 10-Jun-2020 15:04:22

4K+ Views

We can perform mouseover action on elements in Selenium with the help of Actions class. In order to perform the mouse movement we will use moveToElement () method of the Actions class. Finally use build().perform() to execute all the steps.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.interactions.Action; import org.openqa.selenium.interactions.Actions; import java.util.concurrent.TimeUnit; public class MouseOver{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String url = "https://www.tutorialspoint.com/questions/index.php";       driver.get(url);       driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);       // actions class ... Read More

How to count the number of frames in a page in Selenium?

Debomita Bhattacharjee
Updated on 10-Jun-2020 15:02:33

3K+ Views

We can count the number of frames in Selenium by the methods listed below −With the help of List with tagname frame/iframe.With the help of a Javascript executor.ExampleWith tagname.import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import java.util.List; public class FrameCount{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver",       "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String url =       "http://the-internet.herokuapp.com/nested_frames";       driver.get(url);       driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);       //By finding list of the web elements using frame or ... Read More

How to switch to frames in Selenium?

Debomita Bhattacharjee
Updated on 10-Jun-2020 15:00:32

5K+ Views

We can switch to frames in Selenium with the help of the following methods −switchTo()defaultContent()This method is for switching to and fro in between frames and parent frames. The focus is shifted to the main page.switchTo().parentFrame()This method is used to switch the control to the parent frame of the current frame.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class FrameDefault {    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String url = "url with frames";       driver.get(url);   ... Read More

How to handle frames in Selenium?

Debomita Bhattacharjee
Updated on 10-Jun-2020 14:58:33

5K+ Views

We can handle frames in Selenium with the help of following methods −switchTo().frame( frameNumber)This method uses the frame id as the parameter. The index of frame id starts from 0. NoSuchFrameException is thrown if the frame is not found.switchTo().frame( frameName)This method uses the frame name as defined by the developer as the parameter. The frame name is considered a String and is enclosed in quotes. NoSuchFrameException is thrown if the frame is not found.switchTo().frame( WebElement)This method uses the webelement as the parameter. NoSuchFrameException is thrown if the frame is not found. StaleElementReferenceException if the frame is no longer active.Exampleimport org.openqa.selenium.By; ... Read More

How to handle popup windows in Selenium?

Debomita Bhattacharjee
Updated on 10-Jun-2020 14:54:55

1K+ Views

Selenium has getWindowHandles() method , which returns all the window handle ids for all the open windows. This is stored in Set data structure in String data types.In order to navigate to a specific window, we need to traverse to the window we want to access with the iterator() method then switch to that window.getWindowHandle() method gives the window handle id of the current window Id.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import java.util.List; import java.util.Set; import java.util.Iterator; import org.testng.annotations.Test; public class WindowHandles{    @Test    public void windowHandle() throws Exception {       ... Read More

How to handle web based alerts in Selenium?

Debomita Bhattacharjee
Updated on 10-Jun-2020 14:49:12

1K+ Views

Selenium WebDriver gives multiple APIs to handle pop ups or alerts with the help of Alert interface.dismiss()This will cancel the button for alert.accept()This will accept the button for alert.getText()This will extract the text on alert.sendKeys()This will enter text on the alert box.ExampleSyntax with code snippet −// Alert    Alert a = driver.switchTo().alert();    // Extract alert message.    String msg= driver.switchTo().alert().getText();    // print the message on console    System.out.println(msg);    // entering text on alert box    a .sendkeys(“Testing”);    // alert accept    a.accept()    // alert dismiss       a.dismiss()

Advertisements