how can you do right click using selenium?
-
24-09-2019 - |
Question
im trying to preform a right click using selenium, any thoughts on how to do this?
Solution
Please see docroots's answer for selenium.
To generally simulate a right click in JavaScript, have a look at JavaScript simulate right click through code.
OTHER TIPS
According to the OpenQA.Selenium.Interactions
Namespace.
// step 1 - select the element you want to right-click
var elementToRightClick = this.Driver.FindElement(By.Id("elementtoclickonhasthisid"));
// step 2 - create and step up an Actions object with your driver
var action = new OpenQA.Selenium.Interactions.Actions(this.Driver);
action.ContextClick(elementToRightClick);
// step 3 - execute the action
action.Perform();
it appears that for my issue (an element that opens a popup after a right click), using selenium's : mouse_down_right() and then mouse_up_right() worked as well. thanks.
I've tried ActionSequence and it worked.
ContextClick function is not found, you should use click.
So, it should be as follows:
driver.actions().click(element,2).perform();
The element is your web element, 2 means right click.
Selenium is offering a method for right click - ContextClick:
public void RightClick(IWebElement target)
{
var builder = new Actions(driver);
builder.ContextClick(target);
builder.Perform();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow