1

I want to capture the xpath of an element in IE11 through UFT.Is it possible?

Thanks in advance...

user90
  • 141
  • 1
  • 4
  • 11
  • http://meta.stackoverflow.com/questions/269352/asking-about-the-existence-of-a-particular-technique-without-being-too-broad/269359#269359 – Mathias Müller Apr 08 '15 at 09:56

1 Answers1

1

The problem is that there is no the XPath of an element, each element may have multiple XPaths (this is why UFT doesn't supply a default value for the XPath).

You can look for a JavaScript implementation (like the one in this answer) and then use Page.RunScript to get an XPath for your selected element.

The problem is to pass the element to the JavaScript, one way you can use is via IE's `sourceIndex'.

something like this (untested code follows).

Browser("B").Page("P").RunScriptFromFile("C:\defineGetXPath.js")
SrcIndex = Browser("B").Page("P").WebElement("E").GetROProperty("source_index")
XPath =Browser("B").Page("P").RunScript( "getXPath(document.all[" & SrcIndex & "])" ) 
Community
  • 1
  • 1
Motti
  • 110,860
  • 49
  • 189
  • 262
  • Old, but wrong, no? Should be .GetROProperty("attribute/source_index") – TheBlastOne Feb 27 '19 at 18:52
  • 1
    @TheBlastOne no, `source_index` is an _identification property_ that UFT supports for all browsers (not only IE) although I'm not sure how official this support is... using `attribute/` is for getting native properties of the DOM element which UFT doesn't specifically support. – Motti Feb 28 '19 at 07:43