How to Customize Xpath in IE Browser

Generally its hard to find the xpath of an element in IE browser.In order to solve that issue,we can follow these steps.

Customization of X-path in IE Browser

1)Open IE
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)Enter the following in the URL field.

javascript:function getNode(node){var nodeExpr=node.tagName;if(!nodeExpr)return null;if(!=”){nodeExpr+=”[@id='””‘]”;return “/”+nodeExpr;}var rank=1;var ps=node.previousSibling;while(ps){if(ps.tagName==node.tagName){rank++;}ps=ps.previousSibling;}if(rank>1){nodeExpr+='[‘+rank+’]’;}else{var ns=node.nextSibling;while(ns){if(ns.tagName==node.tagName){nodeExpr+='[1]’;break;}ns=ns.nextSibling;}}return nodeExpr;}

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)Enter the following in the URL field for GetXPATH2

javascript:function o__o(){var currentNode=document.selection.createRange().parentElement();var path=[];while(currentNode){var pe=getNode(currentNode);if(pe){path.push(pe);if(pe.indexOf(‘@id’)!=-1)break;}currentNode=currentNode.parentNode;}var xpath=”/”+path.reverse().join(‘/’);clipboardData.setData(“Text”, xpath);}o__o();

13)Repeat Step 9.

Now to get the XPATH of elements 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.

*I got this from some other site but can’t remember which one. Credit goes to the guy who created these JS.

Done,now you can find the Xpath of the WebElement.

9 thoughts on “How to Customize Xpath in IE Browser

  1. Anonymous June 9, 2015 / 7:29 pm

    Wow It Solved my problem. Thankyou :D


  2. Anonymous June 13, 2015 / 1:34 pm

    Hi friend after performing above steps …where we can see the xpath ..could u plz expalin some more clear


  3. suresh June 13, 2015 / 1:36 pm

    After performng above steps…where we can see the xpath of the element …plz exoalin some more clearly


    • charan163 June 13, 2015 / 2:12 pm

      Now you can check it out. ThankYou !


  4. Anonymous June 16, 2015 / 10:56 am

    Could you please come up in detail. For the last step can you provide screenshots, unable to locate the element


  5. Anuhya June 16, 2015 / 11:46 pm

    Wow this is so cool.Thankyou so much.Nice posts. Keep posting !!


  6. Anonymous June 24, 2015 / 10:34 am

    didn’t get anything… I can’t find confirmation to hit allow access button…. Could you pl. help!


    • charan163 June 24, 2015 / 12:37 pm

      Whats the version of IE browser ?


    • vedant kumar February 27, 2017 / 11:07 am

      same problem i m facing


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google 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 )

Connecting to %s