Monday, December 19, 2011

Get XPATH of element in IE

Ever had the need to get the XPATH of an element and you are using IE.  Well, here is how you can:  Create a bookmarklet with the following javascript:

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;}function getXPATH(){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);}getXPATH();

Bookmarklets are just a simple bookmark and you use the script as the url to the site instead of an actual url.  Hope someone else finds this useful.

The code above was adapted from http://functionaltestautomation.blogspot.com/2008/12/xpath-in-internet-explorer.html


Thursday, December 1, 2011

Random thought for the day... Programming in other countries

I had a random thought today while helping someone on my codeplex project (http://spdactivities2010.codeplex.com/):

What language is used to program stuff in other countries?  do they still use english to write their code?  I would assume javascript has to be, since it isnt compoled code, but what about compiled code such as c#?

Hopefully someone with internation experience will hop on here and enlighten me.

-R