有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java除了日志记录之外,在selenium中处理异常还有什么意义吗?

我发现很难理解selenium中异常处理的意义。 例如,如果我试图单击某个元素,但找不到该元素,则会发生NoSuchElementException。 我可以捕捉异常,抛出新的RunTimeException,或者什么都不做。结果将是相同的(程序将失败并停止)

我为什么要费心处理这样一个例外呢

我错过什么了吗

谢谢

    public void clickOnElement(MobileElement element, Integer waitInSeconds){
    waitInSeconds = (waitInSeconds != null ? waitInSeconds : this.secondsToWait);
    try {
        waitFor(ExpectedConditions.elementToBeClickable(element),waitInSeconds);
        element.click();
    } catch (Exception e) {
        System.out.println("Could not click on element");
        e.printStackTrace();
    }
}

共 (0) 个答案