1

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
4

1 回答 1

1

jQueryUI 演示通过 iframe 包含在内。与其他元素不同,您必须明确告诉 Watir 查看框架内部。

您只需要修改脚本以包含框架:

# 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
于 2013-10-03T12:52:50.850 回答