0
我通过webdriver找到元素来测试一个web应用程序,我想知道如果第一个元素没有找到,那么我想继续执行第二个代码,所以我放置了一个最后,但是用我的代码,即使在最终放置之后,代码也会停止执行,并且不会继续第二步。在哪里放置最后在java中的try catch块
请帮忙,谢谢 这里是我的代码:
// ---First Step-----------------------------------------
try {
driver.findElement(By.className("label")).isDisplayed();
System.out.println(" label is displayed");
} catch (NoSuchElementException e) {
System.out.println("label is not displayed");
} finally {
System.out.println("Go to the next step");
}
driver.findElement(By.className("label")).click();
Thread.sleep(3000);
// ---Second Step------------------------------------------
try {
driver.findElement(By.linkText("Resumé")).isDisplayed();
System.out.println("Resumé is displayed");
} catch (NoSuchElementException e) {
System.out.println("Resumé is not displayed");
} finally {
System.out.println("Go to the next step");
}
driver.findElement(By.linkText("Resumé")).click();
你可以请包括你的程序的输出,所以我们可以看到它有多远? – clearlyspam23
例如,如果程序没有找到webelement“label”,它应该显示消息“label is not displayed”,它将继续执行第二步。 – user3745193
好的,但它在运行时实际显示的是什么?它显示“标签不显示?”它显示的是什么?如果没有,还有什么? – clearlyspam23