I have the following WebElements:
<input id="" type="checkbox" value="/p1/foobar1" name="checkbox1" partition="p1" onclick=""/>
<input id="" type="checkbox" value="/p1/foobar" name="checkbox2" partition="p1" onclick=""/>
<input id="" type="checkbox" value="/p2/foobar2" name="checkbox3" partition="p2" onclick=""/>
And I'm wanting to find the 2nd element in the above source (the one with with a value of /p1/foobar
) based on value attribute using regex in an xpath. I have tried the following:
driver.findElement(By.xpath("//input[matches(@value,'.*\\/foobar$')]"));
But it throws an InvalidSelectorException. I've gotten it to work with cssSelector like so ...
driver.findElement(By.cssSelector(input[value$='\\/foobar']));
But I'm still curious how to accomplish this with xpath. Any suggestions?
EDIT: I should also note that I want to be able to find this element without knowing the characters before the last slash (aka /p1/
)