硒继续存在,未发现此类元素

时间:2019-07-11 06:38:35

标签: java maven selenium

如果一个测试用例没有找到或不可点击,如何设置硒以继续其他测试用例?所有实现都使用Java。

请帮助。谢谢。

编辑: 如何将捕获测试用例标记为“失败”?

2 个答案:

答案 0 :(得分:0)

使用Java的简单try / catch块:

package nicholas;

import org.openqa.selenium.ElementNotInteractableException;
import org.openqa.selenium.NoSuchElementException;

public class Nicholas {

    public static void main(String[] args) {

        try {
            // your code containing element-handling methods
        }
        catch(NoSuchElementException | ElementNotInteractableException e) {
            // here comes the code covering exceptions. It can stay empty.
        }

    }

}

答案 1 :(得分:-1)

即使在调用NoSuchElementExceptionclick()出现一个{em> Test Cases 错误,也要继续其他 Test Cases ,则需要包装代码在try-catch{}块中,如下所示:

try {
    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.nsg-button"))).click();
    System.out.println("Element was clicked");
}
catch(TimeoutException e) {
    System.out.println("TimeoutException");
}