Senthilvel
Senthilvel

Reputation: 271

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,

Upvotes: 3

Views: 6000

Answers (1)

Affi
Affi

Reputation: 152

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

Upvotes: 1

Related Questions