Wednesday, March 4, 2009

Getting elements – Firebug to the rescue

In using Watir, probably one of the biggest challenges is accessing elements that are buried inside several layers of Ajax/HTML.  You can run the show_all_objects() method, but that doesn’t always show everything on the page, and it can be difficult to parse through manually.  So what’s a test developer to do?

Firebug to the rescue.

Firebug is a Firefox plugin that provides several useful tools, but one is that it has a great DOM inspector that allows you to easily copy any HTML element on a page by simply clicking the “Inspect” button and clicking on the element to be inspected.  It then allows you to easily copy the element text to the clipboard.

I will often use Firebug and watir-console together when building a test method.  There are times when I’m not sure of the best way to access an element, but with watir-console and Firebug running, I can experiment and fiddle with different code blocks, and find out what will work best.

Check it out here.

Here’s a screenshot:

firebug

No comments:

Post a Comment