我想使用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