简体   繁体   中英

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. HTML looks basically like this:

<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) . How can I do this?

使用此xpath选择器,这是选择文本时的最佳方法

//span[@class='item_selection_number'][contains(text(),'B')]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM