I have used ends-with function as (By.xpath("//input[ends-with(@id,'_PHONE$']"));
But it didnot work
The ends-with
function is part of XPath 2.0 but browsers generally only support 1.0.
So, if you strictly want to fetch all elements that ends with a specific pattern, you can either fetch all elements that contain that pattern (using the contains()
function) and then strictly check the suffix of the id
(fetch the attribute value by .getAttribute("id")
) using Java's .endsWith()
method.
Or
You can use string-length
function, substring
function and equals to get this XPath:
"//input[substring(@id, string-length(@id) - string-length('_PHONE$1') +1) = '_PHONE$1']"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With