valid xpath expression from html

Question:

i ha ve this html

<yt-formatted-string id="text" class="style-scope ytd-button-renderer style-primary size-default">
All
</yt-formatted-string><paper-ripple class="style-scope tp-yt-paper-button">

this xpath works with selenium python

//yt-formatted-string[text()='All']

but how can i include the part id="text" of the html to my xpath expression to be valid
to find with selelnium python

thanks a lot

Asked By: ANNE23

||

Answers:

You can use

//yt-formatted-string[@id='text' and text()='All']

or the more general approach

//yt-formatted-string[@id='text' and contains(text(),'All')]
Answered By: zx485
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.