Still Life

A Series of Mental Snapshots

Watir: Dealing with JavaScript and Frames

Posted by Steve on July 22, 2008

I came across this difficulty when I was trying to automate a webpage that was primarily built in Javascript; this webpage also always had the same href (or web address) and also was built with many frames.  The problem that I ran into was that I could find the links with the IE developer toolbar to get their ids, but whenever I tried to access them, I could not, I was given an error message saying that they did not exist. At this point in time I thought the issue I had was with javascript, but I was incorrect!

A lot of hunting on the interwebs led me, ironically, back to the watir main documentation, where I discovered that my issue was really with frames! When a website has frames, you need to specify what frame the link is in to actually access it, for example:
ie.frame(“main”).link(:id,”UW_CO_JOBTITLE_HL$”).click

Or in general terms:
ie.frame(“FRAMENAME”).link(:id, “LINKID”).click

And there we have, you can now access links that are in frames, hopefully this saves someone all of the hunting that I had to do! This is also a really good example of how difficult it is to find a solution to something when you are not sure what the problem was; I thought the problem was with JavaScript, so I was searching for that, but it was in fact as stated above with the frames!

–Steve

Advertisements

2 Responses to “Watir: Dealing with JavaScript and Frames”

  1. Paul said

    Stumbled on this article looking for an issue I was having with Watir. Not only did it help but it seems we are both trying to automate UWaterloo web sites!

    • Steve said

      Glad that I could help! Watir takes some getting used to, but I have found that once I got around the small quirks it works really well for web automation.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: