I have used ends-with function as (By.xpath("//input[ends-with(@id,'_PHONE$']"));
But it didnot work
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']"
Your id is ending with _PHONE$1 and not _PHONE$. Notice that there is a 1
at the end.
(By.xpath("//input[ends-with(@id,'_PHONE$1']"));
If you still don't want to match that 1 use contains
.
By.xpath("//input[contains(@id,'_PHONE$1']"));
driver.findElement(By.xpath("//id[contains(text(),'PHONE$')]"));
You can use below XPath as well:-
//input[contains(@id,'PHONE$1')]
Hope it will help you :)
Use contains Method
By.xpath("//input[contains(text(), '_PHONE$']");
Or use wait explicit method