我想使用Selenium Webdriver在页面上右键单击并导航上下文菜单。该脚本应该打开右键菜单,并浏览最多2个选项,然后用回车键选择...Selenium Webdriver操作不能使用上下文菜单(右键单击)
driver.Navigate().GoToUrl("http://www.google.com");
//Google search bar
IWebElement tb = driver.FindElement(By.Id("lst-ib"));
Actions action = new Actions(driver);
//Right Clicks outside of the search bar.
action.MoveToElement(tb, -5, -5).ContextClick().Perform();
action.SendKeys(Keys.Up).SendKeys(Keys.Up).SendKeys(Keys.Return).Perform();
单击右侧的执行,因为它应该(在搜索栏之外),但是在此之后,没有证据表明向上箭头被按下,并且没有任何通过返回键选择。菜单选项应该在滚动时突出显示。
我使用的是最新版本的ChromeDriver 2.30,而Chrome 59.0.3071.109
这在ChromeDriver一个已知的问题,我建议使用FirefoxDriver代替:https://bugs.chromium.org/p/chromedriver/issues/detail?id=1003 –
谢谢你,我相信这是这样,因为我在完成其他操作时遇到了麻烦。使用修改键(ctrl + m)作为打开扩展的快捷方式比使用上下文菜单更容易,但这也不起作用...我想我会尝试使用Firefox并等待修复。 – dsidler