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

selenium.click("//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

selenium.click("//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] );
console.dir(node);

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.

117 comments:

  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

    ReplyDelete
  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

    ReplyDelete
  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

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

    ReplyDelete
  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.

    ReplyDelete
  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

    ReplyDelete

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


    Selenium Training in Jayanagar

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

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

    Android Training

    ReplyDelete
  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

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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  24. Your Blog is really awesome with useful information and informative article.Thanks for sharing such a wonderful and excellent post with us.keep updating such a amazing post..
    ISTQB Certification Training Center in Chennai | ISTQB Certification Exams in Velachery | ISTQB Certification Training in Velachery | ISTQB Certification Exams in Madipakkam

    ReplyDelete
  25. Thanks for sharing your wonderful and very useful information.keep updating such a impressive and attractive blog with interesting content.

    Java Training in Chennai | Java Training in Velachery | Java Training Center in Medvakkam | Java Training in Pallikaranai | Java Courses in Chennai | Java Online Training in Guindy

    ReplyDelete
  26. Good article!!! 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…

    Best UI Path Training Institute in Chennai | Best UI Path Training in Velachery | Best UI Path Certification Training in Pallikaranai

    ReplyDelete
  27. Thanks for sharing your informative blog with useful

    information,its really very interesting and happy to read

    your article.keep updating such a wonderful post with

    us..

    Embedded System

    Training in Chennai
    | Embedded Training in

    Velachery
    | Embedded Training

    Institute in Pallikaranai

    ReplyDelete
  28. your Blog is really useful for me,its really very interesting and informative information post.keep updating such an amazing post.
    Linux Certification Training in Chennai | Linux Training Institute in Chennai | Linux Training Center in Adayar | Best Linux Training in Pallikaranai

    ReplyDelete

  29. Your Blog is really amazing; it’s really very informative content and useful information. Thanks for sharing your wonderful blog. Keep updating such a creative knowledge.

    Best Java Training Institute in Chenna | Java Training in Velachery | Best Java Courses in Medavakkam | Java Training Center in Pallikaranai

    ReplyDelete
  30. Your Blog is really amazing,its really useful for me and informative content with helpful information.keep updating such a wonderful post..

    Tally ERP9 Training in Chennai | Best Tally Training in Chennai | Tally Training Center in Pallikaranai | No.1 Tally ERP9 with GST Courses in Velachery

    ReplyDelete
  31. Very informative blog. Helps to gain knowledge about new concepts and techniques.Thanks a lot for sharing this wonderful blog.keep updating such a excellent post..

    Best PCB Design Training in Chennai | No.1 PCB Design Course in Velachery | Best PCB Training in Chennai

    ReplyDelete
  32. Your Blog is really very informative and interesting to read.Thanks for sharing your useful information.keep updating...
    Embedded System Training in Chennai | Embedded Training Institute in Chennai | Embedded Training with IOT in Velachery

    ReplyDelete
  33. Nice blog. Thank you for sharing. The information you shared is very effective for learners I have got some important suggestions from it..
    Python Certification Training Institute in Chennai | Python Training in Chennai | Python Exam Center in Velachery | Python Training in Velachery

    ReplyDelete
  34. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...

    AWS Certification Training Institute in Chennai | AWS Training Center in Chennai | AWS Certification Training in Velachery

    ReplyDelete
  35. Thanks for sharing this information,this is helpful to me a lot...It is amazing and wonderful to visit your site.

    Web Designing Training Institute in Chennai | Web designing Training in Velachery | Web Design Training Center in Velachery

    ReplyDelete
  36. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing.
    Best MicroSoft Azure Training Institute in Chennai | Azure Training in Pallikaranai | Best Azure Certification Training in Pallikaranai | Best Azure Training Center in Chennai

    ReplyDelete
  37. This is a great inspiring article.I am pretty much pleased with your good work. You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post..

    Best ISTQB Certification Training in Chennai | No.1 ISTQB Certification Training Center in Chennai | ISTQB Certification Exam Center in Velachery | ISTQB Certification Training in Saidapet

    ReplyDelete
  38. Thank you so much for posting this. I really appreciate your work. Keep it up. Great work! I am really interested to continue reading your blog. You have shared valid info. Waiting for more updates from you.
    AWS Certification Training in Chennai | Best AWS Training Institute in Chennai | No.1 AWS Certification Training in Nanganallur | AWS Training in Velachery

    ReplyDelete
  39. It is awesome and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    PCB Design Training Institute in Chennai | PCB Designing Training in Velachery | PCB Design in Pallikaranai | PCB Course in Chennai

    ReplyDelete

  40. I feel satisfied to read your blog, you have been delivering a useful & unique information to our vision.keep blogging.
    Regards,

    Azure Training in Chennai
    Azure Training center in Chennai
    Azure courses in Chennai
    R Training in Chennai
    Vmware cloud certification

    ReplyDelete
  41. Good article! 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…
    Python Certification Training in Chennai | Python Training Institute in Velachery | Python Certification Exams in Chennai | Python Exam Center in Chennai

    ReplyDelete
  42. Wow...What an excellent informative blog, really helpful. Thank you so much for sharing such a wonderful article with us.keep updating..

    MatLab Training Institute in Chennai | MatLab Training in Velachery | Matlab Training Center in Chennai | MatLab Courses in Pallikaranai | MatLab Training with Placement in Chennai

    ReplyDelete
  43. I feel really happy to see your blog and look forward to many more entertaining times reading here. Thanks once more for all the details.

    Java Training institute in Chennai | Java Training Center in Chennai | Java Courses in Velachery

    ReplyDelete
  44. It is awesome and wonderful to visit your site.Thanks for sharing your ideas and views... keep rocks and updating........
    Tally ERP9 Training Institute in Chennai | Tally Training Center in Velachery | Tally Training Center in Taramani

    ReplyDelete
  45. I have read your blog its very attractive and impressive. I like it your blog.Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge.

    VMware Certification Training in Chennai | VMware Certification Exam Center in Chennai | VMware Exams Center in Taramani | VMware Certification Exams in Chennai

    ReplyDelete
  46. Wow...What an excellent informative blog, really helpful. Thank you so much for sharing such a wonderful post with us.keep updating..
    AWS Certifications in Chennai | AWS Exam Centers in Chennai | AWS Certification Exams in Velachery | AWS Exams in Velachery | AWS Online Exam Center in Velachery

    ReplyDelete
  47. Very informative and interesting blog, it was so good to read and useful to improve my knowledge as updated one,keep updating..This Concepts is very nice Thanks for sharing.
    ISTQB Certification in Chennai | ISTQB Exam Centers in Chennai | Best ISTQB Exams in Velachery

    ReplyDelete
  48. It is really very awesome and wonderful to visit your site.Thanks for sharing your informative blog with us.keep updating such a wonderful post..
    MicroSoft Azure Certification in Chennai | Azure Exam Centers in Velachery | Azure Exam Centers in Madipakkam

    ReplyDelete
  49. Your Blog is really amazing with useful and helpful content for us.Thanks for sharing.keep updating more information.
    Embedded System Training Institute in Chennai | Embedded Training in Velachery | Embedded System Training in Guindy

    ReplyDelete
  50. Impressive blog with lovely

    information. really very useful

    article for us thanks for sharing

    such a wonderful blog...
    Java Training

    institute in Chennai
    | Java Certification

    Training Center in Velachery
    |

    Java Training in

    Pallikaranai

    ReplyDelete
  51. Nice Post! It is really interesting to read from the beginning and Keep up the good work and continue sharing like this.
    Linux Training Institute in Chennai | Linux Certification Training in Velachery

    ReplyDelete
  52. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision...
    CCNA Training Institute in Chennai | CCNA Training Center in Velachery

    ReplyDelete
  53. Excellent Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge.
    Java Training Institute in Chennai | Java Certification Training in Velachery

    ReplyDelete
  54. Very impressive and interesting blog, it was so good to read and useful to improve my knowledge as updated one,keep updating.
    Embedded System Training in Chennai | Embedded Training Center in Velachery | Embedded Courses in Pallikaranai

    ReplyDelete
  55. Thanks for sharing your wonderful information..Its really impressive and informative content..
    AWS Certification Training in Chennai | AWS Training Institute in Chennai | AWS Exam Center in Velachery

    ReplyDelete
  56. Excellent Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge.
    Embedded System Training in Chennai | Embedded Training in Velachery | Embedded Courses in Pallikaranai

    ReplyDelete
  57. This is useful post for me. I learn lot of new information from your article. keep sharing. thank you for share us.
    MCSE Training Institute in Chennai | MCSE Training in Velachery | MCSE Training Center in Chrompet

    ReplyDelete
  58. Thanks for giving nice information from your blog...It's really an amazing post..
    Selenium Training Institute in Chennai | Selenium Training Center in Velachery

    ReplyDelete
  59. It is amazing blog and good information... I was improve my knowledge... Thanks for sharing such a informative and wonderful post...
    Java Training Institute in Chennai | Java Training Center in Velachery | Java Certification Training in Taramani

    ReplyDelete
  60. Thanks for your informative article. Your post helped me to understand the future and career prospects. Keep on updating your blog with such awesome article.
    PCB Designing Training Institute in Chennai | PCB Training in Velachery

    ReplyDelete
  61. Wow...What an excellent informative blog, really helpful. Thank you so much for sharing such a wonderful article with us.keep updating..
    Hadoop Training Institute in Chennai | Hadoop Training in Velachery | Hadoop Training Center in Chennai

    ReplyDelete
  62. 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.
    Embedded Training Institute in Chennai | Embedded Training in Velachery

    ReplyDelete
  63. This is really too useful and have more ideas from yours. keep sharing many techniques and thanks for sharing the amazing article.
    MatLab Training Institute in Chennai | MatLab Training Center in Velachery

    ReplyDelete
  64. This is the first & best article to make me satisfied by presenting good content. I feel so happy and delighted.By Learn Digital Marketing Course Training in Chennai it will help to get Digital Marketing Course Training in Chennai.Learn Best Digital Marketing Course Training in Chennai's professional institute to get reputed job.

    ReplyDelete
  65. Really nice post. Thank you for sharing your amazing information and informative article,its really useful for us.keep updating such a wonderful blog..
    Embedded Training Institute in Chennai | Embedded Training Center in Velachery

    ReplyDelete
  66. Very informative and interesting blog, it was so good to read and useful to improve my knowledge as updated one,keep updating..This Concepts is very nice Thanks for sharing..
    Selenium Training Institute in Chennai | Selenium Training Center in Velachery | Selenium Courses in T.Nagar

    ReplyDelete
  67. Thanks for sharing your great information..Its really very impressive and informative content.keep updating...
    Linux Certification Training Institute in Chennai | Linux Training in Velachery | Online Linux Training in Madipakkam

    ReplyDelete
  68. Amazing blog. Thank you for sharing. The information you shared is very effective for learners I have got some important suggestions from it..
    Blue Prism Training Institute in Chennai | Blue prism Certification Training in Velachery | Blue Prism Training Center in Adyar

    ReplyDelete
  69. Pretty article! I found some useful information in your blog, it was amazing to read, thanks for sharing this great content to my vision...
    Embedded Training Institute in Chennai | Embedded Training in Velachery | Embedded Certification Training in Velachery

    ReplyDelete
  70. Thank you so much for posting your amazing article...I really appreciate your work. Keep it up. Great work!...keep updating...
    Cloud Computing Training Institute in Chennai | Cloud Computing Training in Velachery

    ReplyDelete
  71. Excellent blog. Thank you for sharing. The information you shared is very effective for learners I have got some important suggestions from it..
    MatLab Training Institute in Chennai | MatLab Training in Velachery | MatLab Training in Taramani

    ReplyDelete
  72. Thanks for sharing this great article! That is very interesting I love reading and I am always searching for informative articles like this..
    Cisco Certification Training in Chennai | Cisco Certification Courses in OMR | Cisco Certification Exams in Velachery

    ReplyDelete
  73. Wow!!..What an excellent informative post, its really useful.Thank you so much for sharing such a awesome article with us.keep updating..
    VMware Certification Training in Chennai | VMware Training Institute in Velachery | VMware Certification Courses in Medavakkam

    ReplyDelete
  74. Amazing blog. Thank you for sharing. The information you shared is very effective for learners I have got some important suggestions from it..
    Embedded System Training Institute in Chennai | Embedded Training in Velachery | Embedded Courses in T.nagar

    ReplyDelete
  75. Great post.Thanks for one marvelous posting! I enjoyed reading it;The information was very useful.Keep the good work going on!!
    Tally Training Institute in Chennai | Tally Training in Velachery | Best Tally Courses in Guindy | Tally Training Center in Pallikaranai

    ReplyDelete
  76. 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.
    Web Designing and Development Training in Chennai | Web Development Training Center in Velachery | Web Designing Courses in Pallikaranai

    ReplyDelete
  77. Awesome post.. Really you are done a wonderful job.thank for sharing such a wonderful information with us..please keep on updating..
    PCB Designing Training Institute in Chennai | PCB Training Center in Velachery | PCB Design Courses in Thiruvanmiyur

    ReplyDelete
  78. Thanks for making me this Blog. You have done a great job by sharing this content here.Keep writing blog this like.
    MatLab Training Institute in Chennai | MatLab Training Center in Velachery | MatLab Courses in Tambaram

    ReplyDelete
  79. Your article is really an wonderful with useful content, thank you so much for sharing such an informative information. keep updating.
    MultiMedia Training Center in Chennai | MultiMedia Training Courses in Velachery | MultiMedia Training Institutes in OMR

    ReplyDelete
  80. Pretty blog, so many ideas in a single site, thanks for the informative article, keep updating more article.
    Software Testing Training Institute in Chennai | Software Testing Training Institutes in Velachery

    ReplyDelete
  81. I am really enjoying reading your well-written articles. It looks like you spend a lot of effort and time on your blog..
    MCSE Certification Training Institute in Chennai | MCSE Training Center in Velachery

    ReplyDelete
  82. Wonderful article..This is very informative blog. Glad to found your blog.Helps to gain knowledge about new concepts and techniques. Thanks for posting information in this blog..
    Linux Certification Training Institute in Chennai | Linux Training Center in Velachery | Linux Courses in Medavakkam

    ReplyDelete
  83. This is useful post for me. I learn lot of new information from your post. keep sharing. thank you for share us..
    Web Designing Training Institute in Chennai | Web Design Taining Center in Velachery | Web Designing Courses in Taramani

    ReplyDelete
  84. Your blog is really useful for me, and I gathered some information from this blog.Thanks a lot for sharing this amazing article..
    CCNP Training Institute in Chennai | CCNP Training Center in Velachery | CCNP Training Courses in Pallikaranai | CCNP Training in Taramani | CCNP Courses in Medavakkam

    ReplyDelete
  85. Thanks for sharing this great article! That is very interesting I love reading and I am always searching for informative articles like this.
    MatLab Training Institute in Chennai | MatLab Training Center in Velachery | Matlab Courses in Adyar

    ReplyDelete