【问题标题】:Unable to automate mouse over using webdriver无法使用 webdriver 自动鼠标悬停
【发布时间】:2013-06-12 17:03:37
【问题描述】:

我无法使用带有以下代码的 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"}

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

【问题讨论】:

  • Yes.org.openqa.selenium.NoSuchElementException: 无法定位元素:{"method":"xpath","selector":"/html/body/form/div[3]/div /div/div[2]/ul/li[4]/div/ul/li[4]/a"} _它没有识别下拉元素。所以菜单中的项目不可见。这就是这个错误的原因.提前致谢
  • 抱歉,由于安全原因,我不能公开发布。除了“操作”之外,还有其他选项可以将控制权授予菜单列表。所以我可以尝试一下。

标签: selenium-webdriver


【解决方案1】:

我看到你没有包含 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-09-22
    • 1970-01-01
    • 1970-01-01
    • 2013-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-04
    相关资源
    最近更新 更多