我想在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();
但移动鼠标时代码不起作用。请给我一些解决方案
试试这个,只是下面发布的vignesh的另一种形式
new Actions(driver).moveToElement(menuHoverLink).perform();
new Actions(driver).moveToElement(subLink).perform();
subLink.click();
而不是直接点击子链接,在子链接上鼠标悬停并单击它,
actions.moveToElement(subLink).click().build().perform();
编辑:注意singe31评论,删除子链接xpath中的。(点),
WebElement subLink = driver.findElement(By.xpath("//*[@id='peopleSubmenu']/ul/li[1]/a"));