我发现很难理解硒中异常处理的意义。例如,如果我尝试单击某个元素,但找不到该元素,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();
}
}
凤凰求蛊
红颜莎娜
犯罪嫌疑人X
相关分类