How can I locate that element with xpath? (class name is not unique).
<a class="my-action" href="/my/path/page.html"></a>
Tried:
//a[@href='/my/path/page.html']
but did not succeed. What is wrong?
You can use contains
like
//a[contains(@href, 'path/page.html')]
Append .
to your XPath if necessary, which means start from current node, not globally.
.//a[contains(@href, 'path/page.html')]
For Selenium, it'd be better to use CSS Selector in your case.
a[href*='path/page.html']
However, you need provide more info on why your XPath doesn't work. Post exception message please. Maybe the issue isn't about partial href in XPath or not. Please avoid XY problem.
example = browser.find_element_by_class_name("my-action"[href*='my']")
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