ruby - Watir Error: unable to locate element -


i writing web scraper watir , can't seem figure out error i'm getting. have array of text links on page, when loop through , click on link , go back, breaks.

here html code

<div>   <a href="wherever">text here</a> </div> <div>   <a href="wherever">text here 2</a> </div> <div>   <a href="wherever">text here 3</a> </div> 

and here watir code

browser = watir::browser.new browser.goto 'some_valid_site.com' array = ['text here', 'text here 2', 'text here 3'] array.each |text|   browser.link(:text, text).click   browser.back end 

it executes first link correctly, when comes second link, following error message:

ruby-2.2.2@gemset/gems/watir-webdriver-0.8.0/lib/watir-webdriver/elements/element.rb:533: in `assert_element_found': unable locate element,  using {:element=>#<selenium::webdriver::element:0x1bef61e9aef3c36a  id="{ad42ba23-8037-a745-8fd7-21955ab49406}">}  (watir::exception::unknownobjectexception) 

i pretty new advice appreciated. thanks!

watir has wait_until_present method:

browser = watir::browser.new browser.goto 'some_valid_site.com' array = ['text here', 'text here 2', 'text here 3'] array.each |text|   browser.link(:text, text).wait_until_present   browser.link(:text, text).click   browser.back end    

default wait time 30 seconds should way more enough. if page isn't reloading on back might need use explicit url.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -