Any Tool to get Xpath, cssSelector to Find a Element in IE

10,265 views
Skip to first unread message

Fayaz Chaudhari

unread,
Feb 28, 2013, 4:33:11 AM2/28/13
to seleniu...@googlegroups.com
Hi Team,

I am unable to find the element in IE.

Is there any tool to find the elements in IE.

I am trying with Fire-IEBrowser1.4 but it's not reponding.

Appreciate if somebody help out.


Thanks,
Fayaz Chaudhari. 

Hari

unread,
Feb 28, 2013, 8:32:54 AM2/28/13
to seleniu...@googlegroups.com
IE8 - F12 to find the element


Regards,
Harikrishnan
> --
> You received this message because you are subscribed to the Google Groups
> "Selenium Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to selenium-user...@googlegroups.com.
> To post to this group, send email to seleniu...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/selenium-users/-/bdLHhHn59eUJ.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Fayaz Chaudhari

unread,
Feb 28, 2013, 9:14:10 AM2/28/13
to seleniu...@googlegroups.com
Hi Hari,

But we couldn't find the xpath in that.

is there any way to find element in using developer's tool??

it's urgent for me.


You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/aIHm3sPbJNM/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.



--
Thanks and Regards,
Fayaz Chaudhari

sirus tula

unread,
Feb 28, 2013, 10:57:52 AM2/28/13
to seleniu...@googlegroups.com
Let me give you this big tool that will probably help you out big time. You need to do following steps.
 
 
1. Download Selnium Builder(new version of selenium ide) in Firefox as plugin from http://sebuilder.github.com/se-builder/. Be aware that selenium builder is still in beta phase so you might encounter some problems. I just use this for getting complex Xpaths or css.
 
2. Once you have it downloaded, try to record and click the element on which you wanted the xpaths or css.
 
3. Then stop the recording and go to the element in the selenium builder tool and select the xpaths or css that you want.
 
After downloading this tool, it has helped me a lot finding XPaths instead of trying myself zillion times to see if i got the correct XPaths.
 
I've attached the snapshot for you all just in case.
Hope that helps!
- "If you haven't suffered, you haven't lived your life."
 
Thanks,
 
Sirus
seleniumbuilderxpaths.PNG

Arran

unread,
Feb 28, 2013, 11:36:27 AM2/28/13
to seleniu...@googlegroups.com
This is a limitation of IE, so thank Microsoft for that.

David

unread,
Feb 28, 2013, 1:36:44 PM2/28/13
to seleniu...@googlegroups.com
I wouldn't call it a limitation of IE, but if applicable maybe limitation of IE & IE addon architecture.

Because Firefox (older versions at least), Chrome, Safari natively don't offer XPath/CSS locator "defining" tools. They only give you an element explorer to see where it is in the source, it doesn't give you the XPath or CSS locator, you still have to download and use tool like Firebug, etc. to assist with that.

So same goes with IE. The developer tools (or my favorite IE tool IEDebugBar, google for it) also will just inspect and show you where element is in source, it won't give you the XPath/CSS for it. And sadly, no third party developer has built an IE addon that provides that missing functionality.

And sirus & all,

you can get XPath/CSS locator values for an element during inspection with Firefox addons like FirePath. I think that's an easier tool to use than Selenium Builder or IDE. Simply because its an FF addon to install. Only go with the builder/IDE if you need more Selenium functionality like record & playback or creating tests out of it. FirePath is great tool for finding locators as well as testing out "tweaked" locators that you modify or define yourself. By testing them out in FirePath to see if there's any matched results returned, you save yourself the hassle of failed Selenium tests/commands because the locator was wrong. FirePath is an improvement upon Firebug for inspecting locators.

sirus tula

unread,
Feb 28, 2013, 1:51:41 PM2/28/13
to seleniu...@googlegroups.com
Agreed, David. I have been using Firepath as well for finding CSS locator or XPath locators. However in Firepath, i still need to write the locator myself and validate if it works correctly or not which is fine since i have been doing it lot of times.
 
However, there are some situations when we need to find the XPath in some 20th row of the table with identical id's and what not. For those situations, i find Selenium Builder more helpful since i can just get the xpath automatically identified by builder so i don't need to write my xpath zillion times and validate it if it works or not.
 
Thanks

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/1CqScQbppZAJ.

For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
 

Arran

unread,
Feb 28, 2013, 2:36:46 PM2/28/13
to seleniu...@googlegroups.com
You can run XPath queries and CSS queries direct into all three of those browser's own developer tools. The only exception is the earlier versions. I know there was a basic Developer Console in Firefox pre version 3. Even then you can still do it before that using direct Javascript. Not nice but it works:

https://developer.mozilla.org/en-US/docs/DOM/document.evaluate 

You don't need any extra addon for it at all.

It is a limitation of IE & it's surrounding architecture if addons cannot be easily shoved into it. This is why Chrome & Firefox sell so well on it - it's an easy to use API and well documented, it is not hard at all to develop your own addon for either of those browsers but IE......

As for the tools to generate the XPath for you... if you need to use tools to generate CSS or XPath queries for you, you are doing it very very wrong. Though Chrome does it natively anyway.

David Lai

unread,
Feb 28, 2013, 2:47:11 PM2/28/13
to seleniu...@googlegroups.com
I haven't looked around at IE plugins, there should be some sort of IE developer tool that can help you.  But if you can't find one, it should be easy enough to create an IE plugin that loads jquery inside a content script to implement your own, you can probably use some parts of the code I'm using for the chrome wtf plugin to build an IE equivalent.


Use the portion of the code below... That is the code that I'm using to intercept clicks and return the xpath, css, id, and name properties of elements.


//Monitor clicks
//Add a doucment level listener for click events.
document.onclick = function(clickEvent) {...

Fayaz Chaudhari

unread,
Mar 1, 2013, 9:47:40 AM3/1/13
to seleniu...@googlegroups.com
HI K.Sreenivasulu,

I tried above method. But It won't work out for me.

Thanks,
Fayaz




On Fri, Mar 1, 2013 at 10:37 AM, <vasu...@gmail.com> wrote:

Hi, i googled for the same and i got it from some where...it worked for me to get xpath in IE8.Its easy..Try it


Way to Get XPATH in IE

Are you stuck with an application that only works in IE?
Do you want the XPATH of an element that can be seen only IE? Unable to replicate the scenario in firefox. There are many firefox addons like xpather, xpath-checker and firebug that will give you the xpath of an element in a second. But sadly there is no addon or tool avaialable that will do this for IE. For most cases you can get the xpath of the elements that fall in your script using the above tools in firefox and tweak them a little (if required) to make them work in IE. But if you are testing an application that will work only in IE or the specific scenario or page that has this element will open-up/play-out only in IE then you cannot use any of the above mentione tools to find the XPATH.
Well the only thing that works in this case is the Bookmarklets that were coded just for this purpose. Bookmarklets are JavaScript code that you will add in IE as bookmarks and later use to get the XPATH of the element you desire. Using these you can get the XPATH as easily as you get using xpather or any other firefox addon.

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.


Thanks
K.Sreenivasulu
--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/aIHm3sPbJNM/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/pkkGMXqGSP4J.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

David

unread,
Mar 2, 2013, 1:50:13 PM3/2/13
to seleniu...@googlegroups.com
>> However, there are some situations when we need to find the XPath in some 20th row of the table with identical id's and what not. For those situations, i find Selenium Builder more helpful since i can just get the xpath automatically identified by builder so i don't need to write my xpath zillion times and validate it if it works or not.

sirus, I haven't yet tried out Selenium Builder. Are you telling me that the XPath/CSS locators returned by the builder are good enough that you don't have to modify them? Using FirePath, Firefinder, and like tools as well as the old Selenium IDE, they never returned ideal locator values. Sure the values worked, but they're not clean and well structured. Does the builder now solve that or you still have to clean them up? e.g. does builder still start XPaths with "//*/div/blah" and contain node indexes like it does in FirePath and IDE?

And did you ever try finding/inspecting elements with FirePath which gives you the XPath/CSS value? As far as I know, FirePath (XPath mode) mostly finds the elements I'm looking for. I just need to clean up or redefine to a better XPath later but the initial value works and locator is found. I've only had trouble with CSS, as it often will detect multiple elements as it seems the CSS detector isn't built as well as the XPath one for finding complex elements. So for XPath with FirePath, you don't need to write your own locator, if you don't care to clean it up.

David

unread,
Mar 2, 2013, 1:56:17 PM3/2/13
to seleniu...@googlegroups.com
Thanks for the tip Arran. I must say, if we're talking about executing Javascript, then users might as well try other easier javascript browser DOM methods, where appropriate like

document.getElementById, document.getElementsByClassName, document.getElementsByTagName, document.getElementsByName, injecting (jQuery library) or making use of jQuery (in the web app already) to find locators

and if you search around the net enough, you'll find some implementations of document.getElementByXPath, there might be CSS equivalent as well

David

unread,
Jun 28, 2013, 8:19:53 PM6/28/13
to seleniu...@googlegroups.com
Since my last post, I came up with some ways to test for XPath and CSS, the post also has links to some other tools/techniques for "finding" (not testing/verifying) XPath and CSS for IE:

anurag....@gmail.com

unread,
Mar 15, 2019, 3:32:03 AM3/15/19
to Selenium Users
Hey Fayaz its not working. No new notepad file is opening nothing.
Reply all
Reply to author
Forward
0 new messages