Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Not directly from WebDriver, but you can fake it if you really need to:</p> <pre><code>public String getElementXPath(WebDriver driver, WebElement element) { return (String)((JavascriptExecutor)driver).executeScript("gPt=function(c){if(c.id!==''){return'id(\"'+c.id+'\")'}if(c===document.body){return c.tagName}var a=0;var e=c.parentNode.childNodes;for(var b=0;b&lt;e.length;b++){var d=e[b];if(d===c){return gPt(c.parentNode)+'/'+c.tagName+'['+(a+1)+']'}if(d.nodeType===1&amp;&amp;d.tagName===c.tagName){a++}}};return gPt(arguments[0]).toLowerCase();", element); } </code></pre> <p>The Javascript is from <a href="https://stackoverflow.com/questions/2631820/im-storing-click-coordinates-in-my-db-and-then-reloading-them-later-and-showing/2631931#2631931">this post</a>, minified to fit on one line. It may not be perfect, but could give you an idea of where to go. Most drivers implement the <a href="http://webdriver.googlecode.com/svn/javadoc/org/openqa/selenium/JavascriptExecutor.html" rel="nofollow noreferrer"><code>JavascriptExecutor</code></a> interface and have the capability of executing Javascript in the browser. <code>executeScript</code> can return any primitive JavaScript type, an HTML element, or non-nested list of any of the preceding.</p> <p><a href="http://code.google.com/p/selenium/wiki/XpathInWebDriver" rel="nofollow noreferrer">Not all browsers support xpath the same way</a>, so be careful if using these xpaths to select elements. Also, not all browsers have native xpath support (<em>cough</em> IE <em>cough</em>), so it was faked in that case. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload