Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/326.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/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
Java webdriver findElement抛出NoTouchElementException,即使其内部是try/catch_Java_Selenium_Webdriver - Fatal编程技术网

Java webdriver findElement抛出NoTouchElementException,即使其内部是try/catch

Java webdriver findElement抛出NoTouchElementException,即使其内部是try/catch,java,selenium,webdriver,Java,Selenium,Webdriver,当驱动程序找不到元素“error row”时,这个方法抛出NoTouchElementException有一个问题。我在两种情况下使用这种方法。一个应该返回true,另一个应该返回false。有人知道它为什么抛出异常吗 public boolean isErrorMessagePresent() { try { driver.findElement(By.className("error-row")); return true; } catch (

当驱动程序找不到元素“error row”时,这个方法抛出NoTouchElementException有一个问题。我在两种情况下使用这种方法。一个应该返回true,另一个应该返回false。有人知道它为什么抛出异常吗

public boolean isErrorMessagePresent() {
    try {
        driver.findElement(By.className("error-row"));
        return true;
    } catch (NoSuchElementException e) {
        return false;
    }
}
编辑:


我将NoSuchElementException指向java.util库。改为:catch(org.openqa.selenium.NoSuchElementException e),它成功了

看一看。看起来您正在从另一个命名空间捕获
NoTouchElementException
。例如,我认为您在类中导入了错误的“NoTouchElementException”类。请确保“org.openqa.selenium.NoSuchElementException”您导入了此软件包您好,谢谢!这确实是问题所在:)更新了答案