3

Is there any way I can check whether a particular page completely loaded or not using Watir?

I tried with browser.status but it's not printing anything.

undur_gongor
  • 15,657
  • 5
  • 63
  • 75
RAJ
  • 898
  • 7
  • 16
  • Depending on what you mean by completely loaded? – Andreas Waldahl May 06 '15 at 09:04
  • Looking at [watir-spec](https://github.com/watir/watirspec/blob/master/browser_spec.rb), `#status` is browser-dependent. But--FWIW--that method doesn't seem to work for me on any browser (and I can't recall ever using it). – orde May 07 '15 at 00:26

1 Answers1

3

Depending on what you mean by completely loaded? All HTML or all HTML and JavaScripts.

For HTML

browser = Watir::Browser.new
#To check if page has been loaded
ready = browser.ready_state.eql? "complete"
#To wait until page has been loaded
browser.wait

For JavaScript and HTML. For these you have to wait for each specific element This code will wait until the element i enable, meaning clickable.

browser = Watir::Browser.new    
browser.text_field(:id => 'id_of_object').wait_until_present
  • hi, First of all, I was asking the watir code, not selenium code and then Even I know this waiting code something like b.text_field.when_present.set() or I could use wait_until_present, but I don't want this, When I check the browser, if the page is being loaded, then it needs to tell me false, it's loaded completely then it needs to be tell me true. – RAJ May 06 '15 at 12:07
  • Ad stated you can only check if the HTML has been loaded. If you have javascripts loading afterwards it will not wait for them. Then you have to wait for the specific element – Andreas Waldahl May 07 '15 at 06:48
  • hi, I have executed your code but it throws the following error for me. "`
    ': undefined method `ready_state' for # (NoMethodError)
    – RAJ May 07 '15 at 18:23
  • What are your gems version number? – Andreas Waldahl May 08 '15 at 08:45
  • watir (4.0.2 x86-mingw32) watir-classic (3.7.0) watir-webdriver (0.7.0) – RAJ May 08 '15 at 09:05
  • hi I tried with 'watir (5.0.0 x86-mingw32, 4.0.2 x86-mingw32) watir-classic (4.0.1, 3.7.0) watir-webdriver (0.7.0)' as well, but throws the same error "`
    ': undefined method `ready_state' for # (NoMethodError)"
    – RAJ May 08 '15 at 09:12
  • Can you check this? lib/watir-webdriver/browser.rb for ready_state – Andreas Waldahl May 08 '15 at 10:46
  • hi, Thank you very much, Actually I was using WATIR instead of WATI-WEBDRIVER, that's what I haven't gotten the output, As soon as I use the WATIR-WEBDRIVER, it's reported correctly. But is it not possible in WATIR? – RAJ May 08 '15 at 12:57
  • Watir almost doesnt have any functions at all. See [Watir Doc](http://www.rubydoc.info/gems/watir/Watir) – Andreas Waldahl May 08 '15 at 13:42
  • Okay, I am scared to use this watir-webdriver because it doesn't provide the way to attach the browser like Watir::IE.attach(:index,0). – RAJ May 08 '15 at 13:46
  • See link for ways to do it in watir-webdriver. [link](http://h3manth.com/content/watir-webdriver-attach-window) – Andreas Waldahl May 08 '15 at 13:47
  • Also see this [link.](http://stackoverflow.com/questions/26386418/how-to-use-attach-an-existing-browser-using-selenium) – Andreas Waldahl May 08 '15 at 13:49
  • hi, I know of this link before 'http://h3manth.com/content/watir-webdriver-attach-window', But it's not working for me, did you try that out by yourself? If I opened more than browser, I can't connect to the previous browsers as he explained in his article, Could you please try that out and let me know whether it's working for you? – RAJ May 09 '15 at 13:11