Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle 'connection has timed out' in Selenium Webdriver

For Ex, I am accessing url in selenium Webdriver, its showing as 'connection has timed out' but my code keep on executes & trying to find mail-Id, its not throwing any exception and showing error as

'Unable to locate element:{"method":"id","selector":"hotel_dest"}'

driver.get("http://192.168.0.151/holidaysonclick/");  
driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);   
driver.findElement(By.id("mail")).clear();

How to handle this Issue,

like image 690
Senthilvel Avatar asked Dec 05 '25 09:12

Senthilvel


1 Answers

You should try to increase the timeout to ensure that the objects are available to selenium to work.
If you want to handle the error, better include this code in @BeforeTest or @BeforeSuite annotation which ensure the entire test suite will not run if this fails.
You can also use try/catch to catch the error and throw exception. Choose whatever is best solution in your case

like image 134
Affi Avatar answered Dec 07 '25 22:12

Affi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!