Reputation: 41
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?
Upvotes: 4
Views: 8144
Reputation: 1
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();
Upvotes: 0
Reputation: 41
There are 2 ways to double click on element:
using DefaultActionSequenceBuilder
class
IActionSequenceBuilder action = new
DefaultActionSequenceBuilder(driver);
action.DoubleClick(element).Build().Perform();
or using WebDriverBackedSelenium
class
ISelenium 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.
Upvotes: 4