I need to find the xpath of the help button for my automation tests.
Here is the HTML element:
<button data-component-id="nokia-react-components-iconbutton" tabindex="0" mode="dark" type="button" xpath="1"></button>
<svg viewBox="0 0 24 24" xpath="1">
</svg>
I tried with this XPath, but it didn't work:
//*[@data-component-id="nokia-react-components-iconbutton"]//svg[contains(@class,"HelpOutline")]
I thank you in advance.
CodePudding user response:
If you want to select the <button>
element before the <svg>
, try the following XPath:
//*[@data-component-id="nokia-react-components-iconbutton" and following-sibling::svg[1][contains(@class,"HelpOutline")]]
CodePudding user response:
Try this XPath to locate button:
'//*[name()="svg" and contains(@class,"HelpOutline")]/preceding-sibling::button'
Note that svg
tag is not a part of standard HTML-namespace, so //svg
won't work. You need to use //*[name()="svg"]
instead