Selenium
How to Verify Tooltip using Selenium WebDriver
Tooltip in Selenium A Tooltip in Selenium is a text that appears when a mouse hovers over an...
Double click action in Selenium web driver can be done using Actions class. Actions class is a predefined class in Selenium web driver used to perform multiple keyboard and mouse operations such as Right Click, Drag and Drop, etc.
Double click in Selenium using Actions class
Actions actions = new Actions(driver);
WebElement elementLocator = driver.findElement(By.id("ID"));
actions.doubleClick(elementLocator).perform();
Right click action in Selenium web driver can be done using Actions class. Right Click operation is also called Context Click in Selenium. Pre-defined method context click provided by Actions class is used to perform right click operation. Below is the code to demonstrate right click operation using Actions class.
Actions actions = new Actions(driver);
WebElement elementLocator = driver.findElement(By.id("ID"));
actions.contextClick(elementLocator).perform();
Test Scenario
Code:
package test;
import 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.Actions;
import org.openqa.selenium.Alert;
public class DobuleClickDemo {
public static void main(String[] args) throws InterruptedException {
WebDriver driver;
System.setProperty("webdriver.chrome.driver","X://chromedriver.exe");
driver= new ChromeDriver();
//Launch the Application Under Test (AUT)
driver.get("http://demo.gtupapers.com/test/simple_context_menu.html");
driver.manage().window().maximize();
driver.get("http://demo.gtupapers.com/test/simple_context_menu.html");
driver.manage().window().maximize();
//Double click the button to launch an alertbox
Actions action = new Actions(driver);
WebElement link =driver.findElement(By.xpath("//button[text()='Double-Click Me To See Alert']"));
action.doubleClick(link).perform();
//Switch to the alert box and click on OK button
Alert alert = driver.switchTo().alert();
System.out.println("Alert Text\n" +alert.getText());
alert.accept();
//Closing the driver instance
//driver.quit();
}
}
Result:
The button labeled "Double-Click Me to See Alert" is clicked and pop-up is shown
In Eclipse, you see the output in the console
Test Scenario:
Code:
package test;
import 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.Actions;
public class ContextClick {
public static void main(String[] args) throws InterruptedException {
WebDriver driver;
System.setProperty("webdriver.chrome.driver","X://chromedriver.exe");
driver= new ChromeDriver();
//Launch the Application Under Test (AUT)
driver.get("http://demo.gtupapers.com/test/simple_context_menu.html");
driver.manage().window().maximize();
// Right click the button to launch right click menu options
Actions action = new Actions(driver);
WebElement link = driver.findElement(By.cssSelector(".context-menu-one"));
action.contextClick(link).perform();
// Click on Edit link on the displayed menu options
WebElement element = driver.findElement(By.cssSelector(".context-menu-icon-copy"));
element.click();
// Accept the alert displayed
//driver.switchTo().alert().accept();
// Closing the driver instance
//driver.quit();
}
}
Result:
Actions action = new Actions(driver);
WebElement link = driver.findElement(By.ID ("Element ID"));
action.contextClick(link).perform();
Actions action = new Actions(driver);
WebElement link = driver.findElement(By.ID ("Element ID"));
action. doubleClick (link).perform();
Tooltip in Selenium A Tooltip in Selenium is a text that appears when a mouse hovers over an...
Selenium installation is a 3 step process: Install Java SDK Install Eclipe Install Selenium...
What is an Exceptions? An exception is an error that happens at the time of execution of a...
Robot Class Robot Class in Selenium is used to enable automated testing for implementations of Java...
What is Selenium IDE? Selenium IDE (Integrated Development Environment) is the simplest tool in...
Report generation is very important when you are doing the Automation Testing as well as for...