Skip to content

Instantly share code, notes, and snippets.

@acdcjunior
Last active August 21, 2016 14:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acdcjunior/e0ea8e8446e299dc4d46 to your computer and use it in GitHub Desktop.
Save acdcjunior/e0ea8e8446e299dc4d46 to your computer and use it in GitHub Desktop.
What XPath version does a given Selenium WebDriver support?
private String getXPathVersion(WebDriver context) {
try {
By.xpath("/nobody[@attr=lower-case('A')]").findElement(context);
return "2.0";
} catch (Exception e) {
return "1.0";
}
}
private String getXPathVersion(WebDriver context) {
try {
By.xpath("/nobody[@attr=('A'||'')]").findElement(context);
return "3.0";
} catch (Exception e) {
try {
By.xpath("/nobody[@attr=lower-case('A')]").findElement(context);
return "2.0";
} catch (Exception e) {
return "1.0";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment