jQuery.fn.getPath = function () { if (this.length != 1) throw 'Requires one element.';
var path, node = this; while (node.length) { var realNode = node[0], name = realNode.localName; if (!name) break;
name = name.toLowerCase(); if (realNode.id) { // As soon as an id is found, there's no need to specify more. return name + '#' + realNode.id + (path ? '>' + path : ''); } else if (realNode.className) { name += '.' + realNode.className.split(/\s+/).join('.'); }
var parent = node.parent(), siblings = parent.children(name); if (siblings.length > 1) name += ':eq(' + siblings.index(node) + ')'; path = name + (path ? '>' + path : '');
node = parent; }
return path;};//This return is valid since execute_script() executes the given JS in the body of an anonymous functionreturn "done";
<html>
<head><title>Test</title></head>
<body>
<div id="container1">
<p class="testclass">A</p>
<p class="testclass">B</p>
</div>
</body>
</html>Does this generate something useful for any web page? Or is it only of use for the particular page you are looking at?
How does it differentiate two elements with no id and the same set of class attributes?
Could you show us some example input/output?
What happens if (or when) the developers) change the classes on the elements?
I can't help but feel that if you're initiating the call from a WebElement, it would have been better written in the host language (java?) with just WebDriver calls.
To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.