如何使用Java在SeleniumWebDriver中執行鼠標切換功能?我想在下拉菜單上做鼠標操作。當我們懸停在菜單上時,它會顯示新的選項。我嘗試使用XPath單擊新選項。但不能直接單擊菜單。因此,作為手動方式,我試圖在下拉菜單上懸停,然后單擊新選項。Actions action = new Actions(webdriver);WebElement we = webdriver.findElement(By.xpath("//html/body/div[13]/ul/li[4]/a"));action.moveToElement(we).build().perform();
3 回答

慕碼人8056858
TA貢獻1803條經驗 獲得超6個贊
Actions action = new Actions(webdriver);WebElement we = webdriver.findElement(By.xpath("html/body/div[13]/ul/li[4]/a"));action.moveToElement(we).moveToElement(webdriver.findElement(By.xpath("/expression-here"))).click().build().perform();

一只萌萌小番薯
TA貢獻1795條經驗 獲得超7個贊
String javaScript = "var evObj = document.createEvent('MouseEvents');" + "evObj.initMouseEvent(\"mouseover\",true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);" + "arguments[0].dispatchEvent(evObj);";((JavascriptExecutor)driver).executeScript(javaScript, webElement);
添加回答
舉報
0/150
提交
取消