1
votes

I use Watir WebDriver.

I would be grateful if someone could show me how to enter a date into the jQuery Datepicker here:

http://jqueryui.com/datepicker/

The following code returns the error:

unable to locate element, using {:id=>"datepicker", :tag_name=>"input or textarea", :type=>"(any text type)"}

require 'watir-webdriver'
browser = Watir::Browser.new :firefox
browser.goto "http://jqueryui.com/datepicker/"
browser.text_field(:id, "datepicker").set("")
browser.link(:text, "Prev").click
browser.link(:text, "2").click
1

1 Answers

1
votes

The jQueryUI demos are included through an iframe. Unlike other elements, you have to explicitly tell Watir to look inside a frame.

You just need to modify your script to include the frame:

# Go to the demo page
require 'watir-webdriver'
browser = Watir::Browser.new :firefox
browser.goto "http://jqueryui.com/datepicker/"

# Tell Watir to locate the elements within the frame
frame = browser.frame(:class => 'demo-frame')
frame.text_field(:id, "datepicker").set("")
frame.link(:text, "Prev").click
frame.link(:text, "2").click