我正在使用 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/