我正在尝试使用 selenium 进行右键单击,关于如何做到这一点的任何想法?
问问题
32771 次
5 回答
12
根据OpenQA.Selenium.Interactions
命名空间。
// 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();
于 2013-10-01T18:26:07.410 回答
4
请参阅docroots对硒的回答。
要在 JavaScript 中一般模拟右键单击,请查看JavaScript 通过代码模拟右键单击。
于 2010-01-31T12:16:49.827 回答
2
看来,对于我的问题(右键单击后打开弹出窗口的元素),使用 selenium 的 : mouse_down_right() 然后 mouse_up_right() 也可以。谢谢。
于 2010-01-31T14:14:14.890 回答
2
Selenium 提供了一种右键单击方法 - ContextClick:
public void RightClick(IWebElement target)
{
var builder = new Actions(driver);
builder.ContextClick(target);
builder.Perform();
}
于 2017-10-30T13:07:51.937 回答
1
我已经尝试过ActionSequence并且它有效。
没有找到 ContextClick 函数,你应该使用 click。
因此,它应该如下所示:
driver.actions().click(element,2).perform();
该元素是您的网页元素,2 表示右键单击。
于 2017-01-09T19:37:33.963 回答