October 5, 2011

Find XPATH in IE using Java Script

You might work on some site which are only work in IE..then there are no tools to generate xpath for you........

You have to write your own xpath to find the element...There are somany tools to identify XPATH in FF..like xpather, firepath and firebug..etc...

Here is a way to find the XPATH on IE...


STEPS TO INSTAL BOOKMARKLETS
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(node.id!=''){nodeExpr+="[@id='"+node.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.

You are all done!!

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 read this article some where...i didnt remenber exactly from where i read this..it is working fine...i tried it..hope it will be useful for guys who are working on IE sites...

6 comments:

  1. Its really worth thanks !!

    ReplyDelete
  2. I think here:
    http://functionaltestautomation.blogspot.de/2008/12/xpath-in-internet-explorer.html

    But it most looks like butthurt.. It's awful.. Damned IE, Wish you die

    ReplyDelete
  3. It's not my first time to visit this web site, i am browsing this web page dailly and get good data from here all the time.

    My web page :: Orgy Videos Free XXX Videos

    ReplyDelete
  4. Thanks a lot for sharing this with all of us you actually understand what
    you are talking about! Bookmarked. Please also visit
    my web site =). We may have a link exchange contract between us

    Also visit my blog post :: www.teengirlsporn.net

    ReplyDelete
  5. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from Javascript Training in Chennai . or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry. JavaScript Training in Chennai

    ReplyDelete