How to doubleclick and rightclick in WebDriver?
As part of project I am trying to use Selenium 2 for automation. I am facing trouble with the below
How do I double click on a 开发者_运维百科web element using Selenium?
How should I right click on a web element to select an item from the menu pop up?
There are 2 ways to double click on element:
using
DefaultActionSequenceBuilder
classIActionSequenceBuilder action = new DefaultActionSequenceBuilder(driver); action.DoubleClick(element).Build().Perform();
or using
WebDriverBackedSelenium
classISelenium selenium=new WebDriverBackedSelenium(driver, driver.Url); selenium.Start(); selenium.DoubleClick("xpath=" + some_xpath);// you could use id, name, etc.
There is ContextMenu method in
ISelenium
interface you could use for simulating Right click. For instance:ISelenium selenium=new WebDriverBackedSelenium(driver, driver.Url); selenium.Start(); selenium.ContextMenu("xpath=" + some_xpath);// you could use id, name, etc.
Double Click
WebElement ele = driver.findelement(By.id("id_of_element"));
Actions action = new Actions(driver)
action.doubleClick(ele).perform();
Right Click
WebElement ele = driver.findelement(By.id("id_of_element"));
Actions action = new Actions(driver)
action.contextClick(ele).build().perform();
If you want second option on the pop up which opens after performing right click you can use below code
action.contextClick(ele).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).build().perform();
精彩评论