[英]How can I find the text between a span element with no class/id using Selenium in Python?
[英]Python & Selenium: Find element by text in span class
我正在嘗試查找一個元素,但是它沒有任何ID或其他任何內容。 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>
我試圖在每個頁面上找到B元素,但是它的位置每次都不同,所以我不能使用span[1]
或第n-th child(1)
。 我怎樣才能做到這一點?
使用此xpath選擇器,這是選擇文本時的最佳方法
//span[@class='item_selection_number'][contains(text(),'B')]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.