flipkart search bar

endswith method not working in selenium | ends-with method xpath locator

In selenium, for finding a web element in the web page we use locators. Xpath is one of the majorly used locatoe type in selenium. 



There are many methods we could use in Xpath locator which makes the locator type more relaint. contains(), text(), starts-with(), ends-with(). 
G(l
ends-with normally belongs Xpath2.0. Browsers normally take Xpath1.0.

So alternate for ends-with, we can use substring method with little logic. 

Look at the below example. 
Syntax, 
//input[substring(@attributename, string-length(@id) -
 string-length('sample') +1) = 'sample']
Example, 
//input[substring(@id, string-length(@id) -
 string-length('_PHONE$1') +1) = '_PHONE$1']

No comments:

Post a Comment