java - 使用 Java 的 Selenium Webdriver : Exception in thread "main" org. openqa.selenium.ElementNotVisibleException:

标签 java xpath

我正在使用 Webdriver 并尝试单击一个链接(账单),该链接还有一个下拉菜单(我的报价)。要找到帐单,然后单击“我的报价”链接,我使用以下代码:

String xp = "//*[@id='Primary_Navbar-Billing']/a";  // With this xpath I can search on my Firefox browser but using the same in my code gives me an error: 

WebElement menu = driver.findElement(By.xpath(xp));


    driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
    // Initiate mouse action using Actions class
    Actions builder = new Actions(driver);    

    // move the mouse to the earlier identified menu option
    builder.moveToElement(menu).build().perform();

    //identify menu option from the resulting menu display and click
    driver.findElement(By.linkText("My Quotes")).click();

我收到错误:

Exception in thread "main" org.openqa.selenium.ElementNotVisibleException:

最佳答案

您可以尝试这 3 个选项:

  • 添加一个Thread.sleep(YourMilliSecondesTime);在你点击()之前;行动。

  • 使用 Xpath 而不是 By.linkText 来查找链接,Xpath 始终是更好的选择。

  • 或者试试这个:driver.findElement(By.xpath("//span[text()='YOURLINKTEXTEHERE']")).click());如果出于某种原因您没有该元素的良好 xpath。

希望这会有所帮助。 :)

关于java - 使用 Java 的 Selenium Webdriver : Exception in thread "main" org. openqa.selenium.ElementNotVisibleException:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43317170/

相关文章:

xpath 只查询子元素

xpath - 使用 XPath 连接所有子节点

java - Selenium/Java 动态表中第 n 个 td 的 xpath

java - 是否有具有队列限制的 ExecutorService 实现以及用新队列成员替换旧队列成员的选项?

java - 如何创建 List<WebElement> 并单击引发 java.lang.IndexOutOfBoundsException 的选项

java - SpringBoot创建DynamicDataSource : Requested bean is currently in creation: Is there an unresolvable circular reference?

java - 使用用户定义的方法在java中将行打印到控制台

javascript - document.evaluate 在 chrome 和 firefox 中

java - 如何比较一维数组和二维数组

java - 恢复错误编码的字符(Java)