XPATH Support

85 views
Skip to first unread message

Volker

unread,
Sep 2, 2016, 4:27:13 AM9/2/16
to webdriver
Hi All.

And just fro general. Which version of XPATH is supported by Selenium 2.53? Makes it a difference, if the browser is IE, FF or Chrome? Has someone a link with a matrix for Selenium version, Browser and XPATH? Thanks for help.

Volker

Volker

unread,
Sep 2, 2016, 4:32:21 AM9/2/16
to webdriver
forgotten...

Additonal to this. I found a hint to set...

"...try using Selenium's allowNativeXpath("false") to switch over to the JavaScript Xpath interpreter...."

...where can t do this?

I initalize my webdriver in this way:


            switch (browser) {
           
case FIREFOX:
                capability
= DesiredCapabilities.firefox();
                webDriver  
= new FirefoxDriver(capability);
               
break;

           
case CHROME:
               
String webdriverChromeDriver = new MonitoringHelper().getProperty("CHROMEDRIVER");
               
System.setProperty("webdriver.chrome.driver", webdriverChromeDriver);

                capability
= DesiredCapabilities.chrome();
                capability
.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
                capability
.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

                webDriver
= new ChromeDriver(capability);
               
break;

           
case INTERNETEXPLORER:
               
String webdriverIeDriver = new MonitoringHelper().getProperty("IEDRIVER");
               
System.setProperty("webdriver.ie.driver", webdriverIeDriver);

                capability
= DesiredCapabilities.internetExplorer();
                capability
.setCapability(InternetExplorerDriver.LOG_FILE, "C:/Selenium/Logs/IELog.txt");
                capability
.setCapability(InternetExplorerDriver.LOG_LEVEL, org.openqa.selenium.ie.InternetExplorerDriverLogLevel.DEBUG);
                capability
.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);

                capability
.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
                capability
.setCapability(CapabilityType.SUPPORTS_LOCATION_CONTEXT, true);
                capability
.setCapability(CapabilityType.SUPPORTS_FINDING_BY_CSS, true);
                capability
.setCapability(CapabilityType.SUPPORTS_JAVASCRIPT, true);
                capability
.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, "ignore");
                capability
.setCapability(CapabilityType.HAS_NATIVE_EVENTS, true);

                webDriver
= new InternetExplorerDriver(capability);
               
break;

Thanks again...

darrell grainger

unread,
Sep 4, 2016, 8:46:04 PM9/4/16
to webdriver
Before Selenium 2.x (which uses WebDriver protocol) there was Selenium 1.0x. The format for Selenium 1.0x was very different from Selenium 2.x. With Selenium 1.0x you could use allowNativeXpath to specify whether you wanted to use the native XPath or not. However, in Selenium 2.x if you attempt to use this extension it does not do anything. Selenium 2.x defaults to using the native XPath. If you didn't want to use the native XPath, this extension will throw an exception telling you that Selenium 2.x only supports native XPath.

Because Selenium 2.x only uses native XPath, the version of XPath is dependent on the browser. What I have found is it is best to use CSS because it is better supported. Looking to see if XPath 2.0 functions are supported I have found many of the functions aren't supported.

If you have a look at http://darrellgrainger.blogspot.ca/2011/12/selecting-webdriver-locators.html it has a table which shows how you can convert many XPath to CSS. The only time you cannot use CSS is if the XPath uses the CDATA, i.e. the text the user sees in the browser. For example, link text.

Darrell

David

unread,
Sep 5, 2016, 1:20:56 PM9/5/16
to webdriver
Well, I believe you also can't use CSS when you want to navigate back up the DOM ancestor tree, or want better control of navigating sibling nodes (previous vs next sibling), or better find by indexed element support (nth-child and nth-of-type never worked as robustly as XPaths indexes for me), or something likes this "(//yourXpathThatReturnsMultipleMatches)[n]" which gives you the n-th match of whatever match set you've found with XPath.

darrell grainger

unread,
Sep 6, 2016, 8:35:19 AM9/6/16
to webdriver
Thanks for pointing that out. Navigating up the DOM is definitely something you need to use XPath for, e.g. "//td[3]/.." has no equivalent in CSS. It has been a while since I used XPath for locators I forgot about that one.

Also the nth-of-type function in CSS isn't exactly the same thing as the position(n) function or indexing, [n]. So if you are using [n] then you need to completely rethink your locator. 
Reply all
Reply to author
Forward
0 new messages