我有这个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">
该xpath与selenium python 配合使用
//yt-formatted-string[text()='All']
但是我怎么能包括id="的部分呢;文本";将html转换为有效的xpath表达式找到硒蟒蛇
非常感谢
您可以使用
//yt-formatted-string[@id='text' and text()='All']
或更通用的方法
//yt-formatted-string[@id='text' and contains(text(),'All')]