Q.How to handle Context Menu in Selenium ?
- using ContextClick(webelement) of Actions method
Code:
import java.awt.event.ActionEvent;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class ContextMenu
{
public static void main(String[] args) throws InterruptedException
{
WebDriver driver=new FirefoxDriver();
driver.get("http://localhost/login.do");
WebElement link=driver.findElement(By.linkText("Actimind Inc."));
Actions actions=new Actions(driver);
actions.contextClick(link).perform();
Thread.sleep(2000);
actions.sendKeys("t").perform();
}
}
Output:
- using ContextClick(webelement) of Actions method
Code:
import java.awt.event.ActionEvent;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class ContextMenu
{
public static void main(String[] args) throws InterruptedException
{
WebDriver driver=new FirefoxDriver();
driver.get("http://localhost/login.do");
WebElement link=driver.findElement(By.linkText("Actimind Inc."));
Actions actions=new Actions(driver);
actions.contextClick(link).perform();
Thread.sleep(2000);
actions.sendKeys("t").perform();
}
}
Output:

No comments:
Post a Comment