Selenium testing: Get your XPath right with the help of Firebug

Creating Selenium tests you often will find yourself fiddling around with (hopefully not too complex) XPaths. If you are having Firebug installed you can use one of its lesser known features to speed up working with XPaths.

Little example ?

Open up Firebug for this page, select the Console tab and enter the following command into the Firebug command line:
$x(“/html/body/div[2]/div/h1”)
Result:
[h1]
Note: Hover the mouse over the h1 and you will see the corresponding element highlighted in the page.

Even better – to have a look at the inner HTML of the headline element enter:
$x(“/html/body/div[2]/div/h1”)[0].innerHTML

Advertisements
This entry was posted in Misc and tagged , . Bookmark the permalink.

One Response to Selenium testing: Get your XPath right with the help of Firebug

  1. Pingback: Selenium Locator Tips « JodieM.com.au

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