简体   繁体   中英

Watir's ready_state method throws “JavaScript error”

I am testing a website on IE11 using watir-webdriver . I wrote a method that waits until page is fully loaded

def page_loaded?
 until @browser.ready_state.eql? 'complete' do
  sleep 1
 end
end

But sometimes I get "JavaScript error" and on fail screenshot I see that some elements of a page are not loaded, which means that my method did not wait until page is loaded. how can I handle "JavaScript error" ? Is it exception? If yes, what class of exceptions is it? Help is appreciated.

That method is already built into Watir . That being said, the notion of a "page finishing loading" is becoming increasingly meaningless with today's dynamic websites.

I'd need to see a full backtrace of the error and ideally what your code is specifically trying to do when it happens in order to give a specific answer to your question of the specific error. The generic answer, and the one I'm most likely to give you even after I've seen your code, is to not rely on document ready state. Make liberal use of Watir's wait_until_present & when_present methods to be sure you can interact with the elements before you try to do so.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM