Reply
Mon 11 Apr, 2016 05:45 am
I have a javascript function which I am using to retrieve the xpath of an element on click. I want to create an .js file with this function and trigger it from a vb 6 editor. The problem is all the example shown are with creating a new html doc and perform the Click operation. But my requirement is this function should work on any existing page whereever I hover my mouse. Please help. The function to get the xpath of the element is as follows :
"element" parameter in the below code will be the object where I am clicking and hence tis is dynamic
function getXPath( element )
{
var val=element.value;
//alert("val="+val);
var xpath = '';
for ( ; element && element.nodeType == 1; element = element.parentNode )
{
//alert(element);
var id = $(element.parentNode).children(element.tagName).index(element) + 1;
id > 1 ? (id = '[' + id + ']') : (id = '');
xpath = '/' + element.tagName.toLowerCase() + id + xpath;
}
return xpath;
}