Do we have any addons for IE to check xpath for Dynamic web elements??

6,878 views
Skip to first unread message

Rakesh BG

unread,
Jun 26, 2013, 10:02:47 AM6/26/13
to seleniu...@googlegroups.com
Hi All,

      I am automating a web application which is loading only in IE 8,9,10 . All the fields are dynamically generating to identify each element in the application we need to write Xpath.
      Problem here is we don't have any ad-dons for IE ex: Xpath checker for Firefox's  

     I agree that we can write the xpath by seeing the html code but In order to check its working fine or not we need to run the script, its taking to much time to identify a single element.

     Do we have any ad-don's of IE browser to check the Xpath..? Please any one give me solution to resolve this problem or best approach to solve it.


Thanks and Regards,
Rakesh

   

David

unread,
Jun 26, 2013, 10:08:55 PM6/26/13
to seleniu...@googlegroups.com
You can try the following:


but it only works in IE via Firebug Lite console or other types of injected javascript consoles, not the native IE developer tools script console.

This won't help you find XPaths, only test/verify that they work.

Karunanidhi Ethiraj

unread,
Jun 27, 2013, 1:43:04 AM6/27/13
to seleniu...@googlegroups.com

Hi All,

 

I am unable to fine the element values, kindly check the below HTML code and advice.

 

<a title="Haresh Housing" onclick="_gaq.push(['_trackEvent', 'Home Page', 'Haresh Housing', 'Haresh Housing']);" target="_blank" href="http://property.sulekha.com/chennai-saffron-project">

<img border="0" style="border: 1px solid #CCC;" alt="Haresh Housing" src="http://spimg.sulekhalive.com/images/property/haresh_housing.jpg">

 

 

 

Kindly advice which id or name I have use for the particular element select.

 

Rakesh BG

unread,
Jun 27, 2013, 3:29:02 AM6/27/13
to seleniu...@googlegroups.com
Hi David,

     Thanks for the replay I am working out as you suggested,  But I dint get you properly how to verify xpath.



      Where to execute this code ..? How to run this and to check the xpath is valid or not (application only load in IE browser)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
document.getElementByXPath = function(sValue) {
  var a =this.evaluate(sValue, this, null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 
  if (a.snapshotLength >0) { 
  return a.snapshotItem(0);
 }
 }; 
 document.getElementsByXPath = function(sValue){ var aResult = new Array();
 var a = this.evaluate(sValue, this, null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
 for ( var i = 0 ; i <a.snapshotLength ; i++ ){aResult.push(a.snapshotItem(i));
 }
 return aResult;
 };
 document.getElementByCssSelector = document.querySelector;
 document.getElementsByCssSelector = document.querySelectorAll; 

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Can you please explain in steps

Thanks and Regards,
Rakesh 

Karunanidhi Ethiraj

unread,
Jun 27, 2013, 6:42:23 AM6/27/13
to seleniu...@googlegroups.com

Dear All,

Anyone can help me out? On below issue

 

 

Thanks & Regards,

 

Maritime Leadership. All the way

Karunanidhi  E

Teledata Marine Solutions
M + 91 9994789611

E karuna...@teledatamarine.com

 


--
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/msgid/selenium-users/E0A323AEEF92404F97E81B64A2D0236D0259628E4AAA%40souexmb01.TDGLOBAL.INTRA.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

David

unread,
Jun 27, 2013, 10:15:01 PM6/27/13
to seleniu...@googlegroups.com
Rakesh,

Sorry, I may have been mistaken a bit. XPath check still might not work in IE due to lack of XPath engine, you may have to inject one first to then use it. After injecting XPath javascript library (into the page DOM), you can then execute the code snippet I referenced on the blog post, then finally execute a XPath check like

document.getElementByXPath("your value here");

which should then return a result and clicking it should highlight the element on the page

if you use CSS selectors though, then executing the code snippet will work w/o injecting anything else in the browser.

You execute the code in the Firebug lite javascript console (the console section/tab of Firebug Lite. there's a section there to enter code denoted by ">>>" like a command prompt shell).
Message has been deleted

J Crown

unread,
Jun 27, 2013, 11:16:59 PM6/27/13
to seleniu...@googlegroups.com
Hi Rakesh,

Object properties won't change from browsers to browsers, unless it specifically handled for a browser by the development team.

So i suggest to use Firefox(firebug) to take Xpath and then run it on InternetExplorerDriver. And it works fine for me, in any browser. Let me know if it does not work out for you.

With Regards,
JCrown
I Blog here

Karunanidhi Ethiraj

unread,
Jun 28, 2013, 12:52:09 AM6/28/13
to David, seleniu...@googlegroups.com

Hi David,

 

Not yet tried. Will chk and update u .

 

 

 

Thanks & Regards,

 

Maritime Leadership. All the way

Karunanidhi  E

Teledata Marine Solutions
M + 91 9994789611

E karuna...@teledatamarine.com

 


From: David [mailto:mang...@gmail.com]
Sent: Friday, June 28, 2013 7:47 AM
To: seleniu...@googlegroups.com
Cc: Karunanidhi Ethiraj
Subject: Re: unable to find the Element ID and value

 

 Karunanidhi ,

 

Have you tried something like 

 

"//img[@alt='Haresh Housing']" for XPath or "img[alt='Haresh Housing']" for CSS selector?

valm...@gmail.com

unread,
Jun 28, 2013, 6:06:15 AM6/28/13
to seleniu...@googlegroups.com
Hi RBG,
Get the "Fire-IEBrowser1.4.xlsm" Excel Macro from the location below.
It's like a browser which gives you the xpaths and css for elements on the page.
 
 
You will need to enable macros in Excel to open it.
in Excel 2007 File -> Excel Options -> Trust Center -> Trust Center Settings -> Macro Settings ->
 
When you open it in Excel click the HowTo? button to learn how to use it.
 
Valw

RBG

unread,
Jun 28, 2013, 6:16:44 AM6/28/13
to seleniu...@googlegroups.com

Hi Crown,

    Thanks for the replay, Yes object properties wont change from browsers to browser . But our application will not load in Fire Fox browser it is only loading in IE browser 
    I have mentioned it properly in the post.

Regards,
Rakesh

David

unread,
Jun 28, 2013, 1:59:57 PM6/28/13
to seleniu...@googlegroups.com
I recently came across this, it may work for you Rakesh. Don't know if will handle complex XPaths, but at least works for simple XPaths


also, do you know if your application can run on Chrome or Safari? Firefox is not the only one for finding & testing locators, though it works best with Firebug. You can do same with Chrome & Safari too, especially when combined with my blog post about testing locators in other non-FF browsers.

David

unread,
Jun 28, 2013, 8:32:27 PM6/28/13
to seleniu...@googlegroups.com
I updated my blog post mentioned in my first reply, you should now be able to "test/verify" an XPath in IE once you have an XPath to check for, there's just some additional steps to enable that in IE.
Message has been deleted
Message has been deleted
Message has been deleted

RBG

unread,
Jul 2, 2013, 5:35:18 AM7/2/13
to seleniu...@googlegroups.com
Hi David,

      Has you guessed I am using complex Xpath for dynamic generating elements, where all attribute are dynamically generating.

     What I need is to check the xpath in IE Browser as we do in FireFoxs Browser ex:-xpath checker.

     If we submit this xpath  //tr[td[a[contains(text(),'submit')]]]. It should display match found or not in the page.

     By this way we can automate fast. Please refer the attached screen shot.

 

   Our application only and only load's OR runs in Internet Explorer Browser.

     If we are not able recognize the web element faster, Its just a waste of time in writing automation script, by the same time we can do manual testing twice....:)


Regards,
Rakesh BG

David

unread,
Jul 2, 2013, 3:50:53 PM7/2/13
to seleniu...@googlegroups.com
Rakesh,

If you follow my blog post (read the whole post and follow the extra prerequisite instructions for IE at the end), it should tell you the process of how to test for a given XPath in IE, similar to XPath checker. But it won't offer a GUI way to just paste in XPath, you have to paste & type some javascript code. The blog post also has a link to a method to find/give you an XPath that you can also later test/evaluate with.

You can do further testing of the XPath in IE with WebDriver before you actually write/create your Selenium test, but you have to use Python or Ruby for their interactive shell. But that's another discussion topic. I often use this other technique to verify my locators work before finally putting the code in a test. This allow for trial & error exploration of test Selenium code to see if something works or not.

Muneer

unread,
Jul 3, 2013, 9:25:32 AM7/3/13
to seleniu...@googlegroups.com
Hi Rajesh

Try this workaround, I hope this can be helpfull to you and decrease the pain of finding xpath for html code :-)

Rakesh BG

unread,
Jul 4, 2013, 9:19:42 AM7/4/13
to seleniu...@googlegroups.com

Ya Rajesh, Trying to execute the same but I am not getting how to check my xpath script in IE 

Regards,


--
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/edY2Fa3p8U8/unsubscribe.
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.

RBG

unread,
Jul 5, 2013, 2:00:22 AM7/5/13
to seleniu...@googlegroups.com
David,

     Thanks for your suggestion, I follow your block but not able to check my xpath.  I have entered below script in the IE browser console and click on run, 
     Browser din't executed any thing
    


    
    var script = document.createElement("//div[div[a[contains(text(),'submit')"); 
  script.setAttribute("type","text/javascript"); 
  document.body.appendChild(script);



I don't know it is rite way to execute or not, can you briefly explain the step's to check the xpath in IE. 

Regards,
Rakesh

David

unread,
Jul 6, 2013, 12:38:21 AM7/6/13
to seleniu...@googlegroups.com
Rakesh,

Here's an example of what you need to do, in case the blog wasn't clear enough

1. use Firebug Lite for IE (go to console section if not already there, to execute javascript). This won't work in IE developer tools, must use Firebug Lite console.

2. execute following code

var script = document.createElement("script"); 
script.setAttribute("type","text/javascript"); document.body.appendChild(script);

3. now manually wait 1 second or more before continuing (for XPath library to inject successfully into the page for testing with IE)

4. now execute the following commands after the above

document.getElementByXPath = function(sValue) { var a = this.evaluate(sValue, this, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); if (a.snapshotLength > 0) { return a.snapshotItem(0); } }; document.getElementsByXPath = function(sValue){ var aResult = new Array();var a = this.evaluate(sValue, this, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);for ( var i = 0 ; i < a.snapshotLength ; i++ ){aResult.push(a.snapshotItem(i));} return aResult;}; document.getElementByCssSelector = document.querySelector; document.getElementsByCssSelector = document.querySelectorAll;

5. now do your XPath test/check/evaluation like follows:

document.getElementByXPath("//div[div[a[contains(text(),'submit')"); 

6. if the XPath is valid & element exists, you'll see an entry returned below your executed command above in the console. Clicking that result will then highlight it in the browser UI on screen. You'd get something like undefined or null if element not exist (or your XPath has typos or is invalid).

By the way your example XPath has typos, I believe

"//div[div[a[contains(text(),'submit')"

should be meant as

"//div[div[a[contains(text(),'submit')]]]"
Reply all
Reply to author
Forward
0 new messages