Is it possible to find a link that matches to the regular expression?
Here https://demoqa.com/links the 2nd link has a random name that is generated each time with the pattern Home[a-zA-Z]{5}
.
Is there any way to check if link text matches to the RegEx or simply contains substring + smth? XPath //a[contains(text(),'substring')]
or $(partialLinkText("substring"))
do not fit because they will select both Home
and Home[a-zA-Z]{5}
First the regex should include numbers as well:
"Home[a-zA-Z\d]{5}"
, and the only solution I can thing of (at least for now), is to iterate over all link elements that containsHome
:But if you know that your browser supports XPath 2.0, so you can use
matches
function with regex:Maybe worth nothing the following links about XPath 2.0 support in browsers: