0

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

4

2 回答 2

0

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

于 2013-07-30T12:58:55.073 回答
0

如果在 WebDriver 正在寻找与下拉交互时它不可见,则:

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

public Accesor(WebDriver driver,String url){
    this.driver = driver;
    this.driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    driver.get(url);
}

2nd-)尝试等到该特定元素出现(但我不建议这样做): WebElement cBoxOverlay = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("cboxOverlay"))));

3rd-) 如果它是应用程序的一个真正的错误,并且 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();
    }
于 2013-07-30T13:14:05.120 回答