[英]Python & Selenium: Find element by text in span class
I'm trying to find an element, but it doesn't have any ID nor anything else. 我正在尝试查找一个元素,但是它没有任何ID或其他任何内容。 HTML looks basically like this: HTML基本上如下所示:
<div class="item_select">
<span class="item_selection_number">A
</span>
</div>
<div class="item_select">
<span class="item_selection_number">B
</span>
</div>
I'm trying to find the B element on every page, but its position varies every time, so I can't use span[1]
or n-th child(1)
. 我试图在每个页面上找到B元素,但是它的位置每次都不同,所以我不能使用span[1]
或第n-th child(1)
。 How can I do this? 我怎样才能做到这一点?
使用此xpath选择器,这是选择文本时的最佳方法
//span[@class='item_selection_number'][contains(text(),'B')]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.