如何使用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 回答
月关宝盒
TA贡献1772条经验 获得超5个赞
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贡献2012条经验 获得超12个赞
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
提交
取消