Java Webdriver不选择下拉式lsi项

Java Webdriver不选择下拉式lsi项,java,memory,Java,Memory,我得到一个错误org.openqa.selenium.ElementNotVisibleException:元素当前不可见,因此可能无法与之交互。如何解决它?这可能意味着您的元素可见性设置为隐藏。或者也可能意味着元素当前不在视图中,必须滚动到视图中 如果在WebDriver希望与下拉列表交互时不可见,则: 1-)您应该增加隐式等待时间,直到任何控制器出现在UI中: public Accesor(WebDriver driver,String url){ this.driver = dri

我得到一个错误org.openqa.selenium.ElementNotVisibleException:元素当前不可见,因此可能无法与之交互。如何解决它?

这可能意味着您的元素可见性设置为隐藏。或者也可能意味着元素当前不在视图中,必须滚动到视图中

如果在WebDriver希望与下拉列表交互时不可见,则:

1-)您应该增加隐式等待时间,直到任何控制器出现在UI中:

public Accesor(WebDriver driver,String url){
    this.driver = driver;
    this.driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    driver.get(url);
}
第2-)尝试等待特定元素出现(但我不建议): WebElement cBoxOverlay=wait.until(ExpectedConditions.visibilityOf(driver.findelelement)(By.id(“cBoxOverlay”))

3-)如果这是应用程序的一个真正的bug,并且UI没有显示您正在查找的下拉列表,那么请尝试通过截屏并尝试下一个测试用例或测试套件来处理此类异常:

public void takePicture(){
    File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
    // Now you can do whatever you need to do with it, for example copy somewhere
    try {
        FileUtils.copyFile(scrFile, new File("c:\\tmp\\"+ getClass().getName().substring("com.automation.testsuite.".lastIndexOf(".")+1) + ""+new Date().toString().substring(0,10)  +".png"));
    } catch (IOException e) {

        e.printStackTrace();
    }