How to get Watir to return actual HTML when site redirects?
When I read out the HTML开发者_开发技巧 returned by Watir, it gives me a page directing me to come back on a browser through my Mac or PC. It seems I am being redirected by a user agent given through Watir. I thought I was driving the browser with Watir, but this doesn't seem to be the case.
ie = Watir::IE.new
ie.goto "http://www.apple.com/safari/download"
ie.checkbox(:name, "21.1.9.12.3.1.3.0").clear
Which returns an UnkownObjectException. Same with trying to click the submit button.
Using firebug I can find the checkbox fine, that's how I found the :name. So I next redirected the HTML output from Watir into a file for inspection,
myfile = File.new("safaridebug.html", "w+")
myfile.puts ie.html
myfile.close
Looking through safaridebug.html is where I noticed I was on a different page from the web browser. Is there someway in watir I can get the actual HTML that is present in my web browser, maybe a user agent spoof? Thanks.
System Specs: VM running Win XP SP2, ruby 1.8.7, IE 8
Watir is working correctly in that case. There is no special user-agent or anything used by Watir because plain old IE is used and it's user-agent is sent by the IE itself of course.
The reason why you cannot find the checkbox with Watir or from the HTML is that the checkbox is in a frame :) Look for a frame tag in that html and you can understand why you were not able to find it before.
You can access it from the frame instead:
b.frame(:id, "download-frame").checkbox(:name, "21.1.9.12.3.1.3.0").clear
If you're getting access denied errors when trying to access frames, then just read the instructions at http://wiki.openqa.org/display/WTR/Frames
精彩评论