Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Silenium webdriver使用Java:Exception in thread;“主要”;org.openqa.selenium.ElementNotVisibleException:_Java_Xpath - Fatal编程技术网

Silenium webdriver使用Java:Exception in thread;“主要”;org.openqa.selenium.ElementNotVisibleException:

Silenium webdriver使用Java:Exception in thread;“主要”;org.openqa.selenium.ElementNotVisibleException:,java,xpath,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 = dri

我正在使用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();
我得到一个错误:

线程“main”org.openqa.selenium.ElementNotVisibleException中的异常:


您可以尝试以下3个选项:

  • 添加一个线程。睡眠(毫秒);在单击()之前;行动

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

  • 或者试试这个:driver.findElement(By.xpath(//span[text()='yourlinkTextHere'])。单击();如果出于任何原因,您没有适合此元素的xpath


希望这会有所帮助。:)

请阅读-总结是,这不是一个理想的方式来解决志愿者,可能会适得其反获得答案。请不要将此添加到您的问题中。或明确等待或使用Id。许多选项。