1

I am using Watir, Selenium ChromeDriver to run a crawling script in my Rails app. Some of the form elements that I need to complete are revealed conditionally, for example based upon the selection of checkboxes, and some of these conditionally revealed elements render on a fade in, which takes a short while to appear on page.

Currently I'm using sleep to ensure that the element is present by the time Watir tried to manipulate it. This results in a cumulative fair delay in completing the crawl operation which I would like to avoid. What would be the best way for me to reduce these waiting times without erroring out the form?

Example code from the crawling script:

def complete_form_1
        @browser.text_field(name: 'ctl$Years').set '5'
        @browser.text_field(name: 'ctl$CompanyNumber').set '08216084'
        @browser.select_list(:name, "ctl&IndType").select_value("02")
        @browser.radio(:id => "ctl_CurrentIns").set
        sleep 0.25
        @browser.checkbox(name: "ctl$chkLf").set
        sleep 0.25
        # @browser.checkbox(name: "ctl$chkLf").clear
        # sleep 1
        # @browser.checkbox(name: "ctl$chkLf").set
        # sleep 1
        @browser.select_list(:name, "ctl$LfCar").select_value("14")
end

I have just found this SO post; How do I use Watir::Waiter::wait_until to force Chrome to wait?

and am investigating this Watir Module: http://www.rubydoc.info/gems/watir-webdriver/Watir/Wait

Any other thoughts or suggestions welcome.

jbk
  • 1,911
  • 19
  • 36

1 Answers1

1

From versions >6 Watir already waits for the element to be present, version <6 would have needed to use the below:

@browser.checkbox(name: "ctl$chkLf").wait_until_present.set

As defined in the Watir docs here.

I was lead to this from this SO post here.

jbk
  • 1,911
  • 19
  • 36
  • 3
    What version of Watir are you using? Explicitly telling Watir to wait for the field before setting it should no longer be necessary. The 6.x versions should be automatically waiting for the element to be present before setting it. – Justin Ko Jul 24 '17 at 17:41
  • Ah, really, ok thanks @Justin-Ko, Im on 6.4.3. Something else is going on with the crawl script I'm writing which has it fail to select a dropdown item from a list presented by the previous check box then. I shall investigagte and test further then. – jbk Jul 25 '17 at 08:57
  • It's relatively new code, so it is possible there are bugs or scenarios that weren't accounted for. Creating a page that reproduces the problem would help a lot. – Justin Ko Jul 25 '17 at 12:59
  • Wold be great to do that then you guys can have a look at what's going on, but i think the issue is that it's javascript thats running that I can't access on the page to try to see what's going on. – jbk Jul 25 '17 at 15:51