ruby - timeout ie.close not working and time out error occurs -


ie.link(:id, "ctl00_contentplaceholder1_btnsearch").click   rescue timeout::error       #sleep(5)              puts "timeout"             ie.close          #sleep(9)          retry #open new browser , go begin             end` 

when .click link gets time out , output = timeout, ie.close not work. , time out error comes *i want close browser when time out error comes*

i not believe ie.link(:id, "ctl00_contentplaceholder1_btnsearch").click ever throw timeout::error. why rescue block never executed.

the exceptions thrown are:

  • when ie.link(:id, "ctl00_contentplaceholder1_btnsearch").click , element not found, watir::exception::unknownobjectexception occur.
  • when ie.link(:id, "ctl00_contentplaceholder1_btnsearch").when_present.click , element not found within required time frame, watir::wait::timeouterror occur.

your rescue needs catching 1 of these exceptions instead.

begin   ie = watir::browser.new   ie.goto 'www.yourpage.com'   ie.link(:id, "ctl00_contentplaceholder1_btnsearch").click rescue watir::exception::unknownobjectexception   puts "element not found"   ie.close   retry #open new browser , go begin end 

or if using when_present on element:

begin   ie = watir::browser.new   ie.goto 'www.yourpage.com'   ie.link(:id, "ctl00_contentplaceholder1_btnsearch").when_presentclick rescue watir::wait::timeouterror   puts "element did not appear in time"   ie.close   retry #open new browser , go begin end 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -