Skip to content

Instantly share code, notes, and snippets.

View 4M01's full-sized avatar
🏠
Working from home

Amol Chavan 4M01

🏠
Working from home
View GitHub Profile
@4M01
4M01 / getAbsoluteXPath.java
Last active December 17, 2017 19:57
This method accepts webelement as parameter and returns absolute XPath string.
public static String getAbsoluteXPath(WebElement element){
return (String) ((JavascriptExecutor) driver).executeScript(
"function absoluteXPath(element) {"+
"var comp, comps = [];"+
"var parent = null;"+
"var xpath = '';"+
"var getPos = function(element) {"+
"var position = 1, curNode;"+
"if (element.nodeType == Node.ATTRIBUTE_NODE) {"+
"return null;"+