0
   

Clicking an element on existing page

 
 
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;
}
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Question • Score: 0 • Views: 658 • Replies: 0
No top replies

 
 

Related Topics

 
  1. Forums
  2. » Clicking an element on existing page
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.03 seconds on 04/26/2024 at 05:11:24