Wednesday, July 21, 2010

Selenium, XPath, and Firebug

Armed with Selenium, Xpath, and Firebug you're ready to automate almost any web test case. Looking at the Selenium Reference guide most of the actions take a locator. The easiest locator to use is the id attribute of the element you are performing the action on. If you or you're team are developing with automated web tests in mind, then there should be an id on all the significant elements. If there is no id on the element, don't fret you can use my next favorite locator: XPath.

Here's a tutorial to XPath if you are not familiar with the language.


Okay so now you've got your selenium script and the xpath of that link inside the table you want to click (for example). You run your selenium script and it errors saying the element you're trying to click does not exist or could not be found. You go back to your script and try to figure out what's wrong with your XPath expression"//table/td/a[contains(.,'Important link')]");

In my head I'm thinking "Click on the cell that contains the link that says Important link". What the heck is wrongs with this code?!? After trial and error you figure out it's missing the tr in the path"//table/tr/td/a[contains(.,'Important link')]");

When I first started with XPath and Selenium I would spend hours developing the XPath expression, run the selenium test, watch it fail on the XPath command, edit it, and repeat till it worked. This was an inefficient use of time and brain power.

That's when Firebug came in to save the day. Firebug has an awesome console where you can do javascript debugging and object inspection. Using the console you can test your XPath expression and determine if the element actually exists before putting it into your selenium script. To use it navigate to the page you want to test and then open up firebug. Click on the console tab, then click on the little red triangle pointing upward to expand the console. Inside the console you can write javascript to evaluate your XPath expression. Fortunately firebug comes with a built in function that evaluates XPath expressions, $x.

Here's the snippet of code I use

var node = $x( [your xpath expression here] );

Click run and if your XPath is valid it should return the dom element allowing you to inspect it. If your XPath is invalid it won't return anything. Here's a screen shot

Now you can test your XPath independently of your selenium script and be sure that your locator is correct. This will save you lots of time and increase your confidence in what your selenium actions are doing.


  1. The future of automation testing tool is on the positive tool. As the demand of quality web application keeps on increasing, the tool like Selenium IDE is getting very popular all over the world. Thus, taking Selenium Training in Chennai will help you to enter software testing industry.Best Selenium training institute in Chennai

  2. The future of software testing is on positive note. It offers huge career prospects for talented professionals to be skilled software testers. Software testing training|Software training|Software testing training in chennai

  3. Excellent article!!! LoadRunner is popular automation testing tool used for validating a software application/system under load. It delivers most precise information about the performance, functionality and behavior of the software product. Loadrunner Training in Chennai | Loadrunner training Chennai|Qtp training Chennai

  4. Excellent sharing. Testing is a wonderful field for IT peoples. Want to learn Selenium Online Training reach GangBoard. Hadoop Online Training

  5. Nice blog. Thank you for sharing. The information you shared is very effective for learners I have got some important suggestions from it. erp in chennai.

  6. Great content thanks for sharing this informative blog which provided me technical information keep posting.Android Training Institute in Chennai | Android Training Institute in Velachery


  7. I believe there are many more pleasurable opportunities ahead for individuals that looked at your site.

    Selenium Training in Jayanagar

  8. Fantastic site. Lots of helpful information here. I¡¦m sending it to several pals ans additionally sharing in delicious. And naturally, thanks on your effort!
    Good Vecation classes in Chennai | Best Summer Course in Guindy

  9. Great information on this blog, many useful and new ideas i'm learning here.It's very helpful....
    Good Technical Boot Camp in Chennai | Best Summer Course in Porur

  10. I am reading your post from the beginning, it was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly.

    software testing course in chennai

  11. Impressive blog with lovely information. really very useful article for us thanks for sharing such a wonderful blog...
    Summer Courses in Perungudi | Summer Courses in OMR | Summer Courses in Velachery

  12. Superb explanation & it's too clear to understand the concept as well,thank you for your sharing...
    No.1 Summer Technical Boot Camp in Chennai | Summer Courses for Hardware and Networking in Velachery

  13. Impressive blog with lovely information. really very useful article for us thanks for sharing such a wonderful blog... Excellent Summer Courses for Business Administration in Chennai | Best Vacation Classes in Chennai

  14. Good and nice information, thanks for sharing your views and ideas..keep rocks and updating.
    Blue prism Exams in Chennai | Blue prism Exam Centers in Chennai | Blue prism Certifications in Chennai

  15. Awesome post. Really you are shared very informative concept... Thank you for sharing. Keep on updating...
    Python Certification Exam Training in Chennai | Best Python Training in Guindy

  16. Well Said, you have furnished the right information that will be useful to anyone at all time.
    ISTQB Certifications Exam institute in Chennai | QA Testing in Sholinganallur

  17. Great Article...Thanks for sharing the best information

    Android Training

  18. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging…
    ECE Project Center in Chennai | BE Project Training in Velachery

  19. Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
    Digital Marketing Training

  20. Amazing Article ! I have bookmarked this article page as i received good information from this. All the best for the upcoming articles. I will be waiting for your new articles. Thank You ! Kindly Visit Us @ Coimbatore Travels | Ooty Travels | Coimbatore Airport Taxi | Coimbatore taxi

  21. Good and more informative post... thanks for sharing your ideas and views... keep rocks and updating.........

    PCB Designing Training in Chennai | PCB Training Institute in Chennai | PCB Training in Velachery

  22. I am really enjoying reading your well-written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work.
    VMware Training in Chennai
    VMware course in Chennai
    Vmware Learning
    Automation Anywhere Training in Chennai
    AWS Training in Chennai
    Azure Training in Chennai
    VMWare Training in Velachery
    VMWare Training in Tambaram
    VMWare Training in Adyar

  23. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge.

    MatLab Training Institute in Chennai | MatLab Training in Velachery | MatLab Courses in Medavakkam