0

我无法使用带有以下代码的 webdriver 自动将鼠标悬停。如果有人给出解决方案,我将不胜感激

Actions builder = new Actions(driver); 
WebElement el=driver.findElement(By.linkText("Account"));
System.out.println(el.getText());
builder.moveToElement(el);
Thread.sleep(5000);
WebElement ele1=driver.findElement(By.xpath("/html/body/form/div[3]/div/div/div[2]/ul/li[4]/div/ul/li[4]/a"));
System.out.println(ele1.getText());
builder.moveToElement(ele1);
builder.click();
builder.perform();
Thread.sleep(5000L);

org.openqa.selenium.NoSuchElementException: 无法定位元素: {"method":"xpath","selector":"/html/body/form/div[3]/div/div/div[2]/ul/ li[4]/div‌​/ul/li[4]/a"}

它没有识别下拉元素。因此菜单中的项目不可见。这就是导致此错误的原因。

4

1 回答 1

0

我看到您没有包含 SUT-而且我看到您遇到了不正确的 xpath 问题。你需要解决这个问题。如果您无法弄清楚真正的 xpath。也许您应该使用 Selenium IDE 从其脚本中获取上下文。

一旦你整理出来。您可以尝试以下方法来刺激鼠标悬停。

WebElement element = driver.findElement(By.xpath("/html/body/form/div[3]/div/div/div[2]/ul/li[4]/div/ul/li[4]/a"));
Locatable hoverItem = (Locatable) element;
Mouse mouse = ((HasInputDevices) driver).getMouse();
mouse.mouseMove(hoverItem.getCoordinates());
于 2013-06-12T09:03:37.207 回答