[英]selenium , java , testing
How can i skip the error and continue with the next iteration in for loop
, i have pasted my code below , what I'm trying is , I'm trying to download multiple PDF from a website , i have used the linkText-FullText PDF which is available for all the PDF exept one , so the loop fails and program stops . 我如何跳过错误并继续进行
for loop
的下一个迭代,我将代码粘贴在下面,我正在尝试的是,我正在尝试从网站下载多个PDF,我使用过linkText-FullText PDF这适用于所有PDF的所有版本,因此循环失败,程序停止。
Error: Exception in thread "main"
org.openqa.selenium.NoSuchElementException: no such element: Unable to
locate element: {"method":"link text","selector":"Fulltext PDF"}
(Session info: chrome=60.0.3112.113)
You can use try catch block to skip the error as given below. 您可以使用try catch块跳过以下错误。
for(;;){
try{
//code to click on link text
}
catch(NoSuchElementException ex){
}
}
You can use any looping condition like for, while with try catch to handle exception with continuous execution 您可以使用for等任何循环条件,同时使用try catch处理连续执行的异常
while(true or condition here){ while(此处为真或条件){
try{
// your code here
}catch(Exception e){
}
} }
or 要么
for(;condition here;){ for(;这里条件;){
try{
// your code here
}catch(Exception e){
}
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.