我想在java中使用selenium webdriver在元素上执行鼠标悬停功能。我正在使用的代码是:
Actions actions = new Actions(driver);
WebElement menuHoverLink = driver.findElement(By.xpath(".//a[@title='Directory'][.='People']"));
actions.moveToElement(menuHoverLink).build().perform();
WebElement subLink = driver.findElement(By.xpath(".//*[@id='peopleSubmenu']/ul/li[1]/a"));
subLink.click();
但移动鼠标时代码无效。请建议我一些解决方案
答案 0 :(得分:1)
不要直接点击子链接,而是在子链接上鼠标悬停并单击它,
actions.moveToElement(subLink).click().build().perform();
编辑:注意歌手31评论,删除子链接xpath中的。(点),
WebElement subLink = driver.findElement(By.xpath("//*[@id='peopleSubmenu']/ul/li[1]/a"));
答案 1 :(得分:0)
试试这个,只是下面发布的另一种形式
new Actions(driver).moveToElement(menuHoverLink).perform();
new Actions(driver).moveToElement(subLink).perform();
subLink.click();