Thursday, 18 April 2013

Getting XPath of Web Elements in Internet Explorer

Testing applications in Internet explorer can be tricky,for one it does not have a tool like Firebug and hence XPath finding can be difficult.But since Javascript has full power over the DOM we can write some scripts to get the element XPath by ourselves.

1)Open Internet Exploer
2)Type about:blank in the address bar and hit enter
3)From Favorites main menu select--->Add favorites
4)In the Add a favorite popup window enter name GetXPATH1.
5)Click add button in the add a favorite popup window.
6)Open the Favorites menu and right click the newly added favorite and select properties option.
7)GetXPATH1 Properties will open up. Select the web Document Tab.
8)Copy and Paste the JavaScript Snippet one code from my Git hub repository in the URL field.

9)Click Ok. Click YES on the popup alert.
10)Add another favorite by following steps 3 to 5, Name this favorite GetXPATH2 (step4)
11)Repeat steps 6 and 7 for GetXPATH2 that you just created.
12)Copy and Paste the JavaScript Snippet two code from my Git hub repository in the URL field for GetXPATH2.

13)Repeat Step 9.

Javascript Snippet one code:

Javascript Snippet two code :


You are all done!!

Now to get the XPATH of an element just select the element with your mouse. This would involve clicking the left mouse button just before the element (link, button, image, checkbox, text etc) begins and dragging it till the element ends. Once you do this first select the favorite GetXPATH1 from the favorites menu and then select the second favorite GetXPATH2. At his point you will get a confirmation, hit allow access button. Now open up a notepad file, right click and select paste option. This will give you the XPATH of the element you seek.

This has a limitation however on selecting web elements which  are like menu elements within a drop down box,hidden elements etc.But comes in very handy on a general usage scenario.

By no means this is the best way to work with locators in IE.Good stable locators are often hand crafted and carefully chosen using Xpath functions and other advanced strategies.But this is good as a starting point and to build upon further



  1. You can test XPaths in IE with this technique:

  2. This comment has been removed by the author.

  3. Doesn't work. after selecting element, if I choose a favorite, it just navigates to this favorite. Cannot see what I,m doing wrong.

  4. Hi,

    Can u please upload a video of the above steps.

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