[英]Fastest way to kill NoSuchElementException or any Exception when element is not found in Selenium WebDriver
Is there a fastest way to kill the process in catch
(when using try/catch)? 有没有最快的方法来终止catch
的进程(使用try / catch时)? Cos usually it takes 1 minute to make the process proceed after exception has been caught. Cos通常在捕获到异常之后需要1分钟才能使该过程继续进行。
I have this code below: 我在下面的代码:
public boolean elementExist(WebDriver driver, By locator){
boolean exist = false;
try{
exist = driver.findElements(locator).size()>0;
} catch (org.openqa.selenium.NoSuchElementException e) {
return false;
}
return exist;
}
Whenever the script didn't found the element it waits 1 minute to proceed. 每当脚本未找到该元素时,它都会等待1分钟以继续。 I need to lower down the 1 minute to at least 5-10 secs bcos it's such a waste of time. 我需要将1分钟的时间降低到至少5-10秒,因为这样很浪费时间。
Or if there's another way and faster to handle if the element does not exist please help. 或者,如果不存在该元素,还有另一种更快的处理方法,请提供帮助。
Try to set 尝试设定
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
Right after 之后
WebDriver driver = new FirefoxDriver(); //or ChromeDriver
ImplicityWait basically tells Selenium "Hey, every operation you are trying to perform should Timeout after 3 seconds" ImplicityWait基本上告诉Selenium:“嘿,您要执行的每个操作都应在3秒后超时”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.