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.