With Selenium/python 如何点击符合特定条件的按钮

With Selenium/python how to click buttons who match a certain condition

我目前正在使用 Selenium 和 Python 创建一个脚本来帮助在网站上预订免费实习点,这样您就不必一直检查它。

我找到了可点击的元素,但现在我不知道如何添加条件。我想将文本属性设置为条件,它位于“按钮”下方的 td 标签下,但不知道如何操作。它显示了可用的位置总数(x/y,所以我将其设置为 1/ )。有可能吗?

也许我可以用绿色来做,但我找不到它在 HTML 文档中的锚定位置

browser.get('https://www.pj-portal.de/index_hro.php?PAGE_ID=101')

delay = 2


browser.find_elements_by_xpath("//*[starts-with(text(),'1/')]")
print("found")
Liste1 = browser.find_elements_by_xpath("//*[starts-with(text(),'1/')]")
print(len(Liste1))

B = browser.find_element_by_xpath("//img[@src='images  /wunsch_setzen_button.svg']")
B.click()
print("button")

HTML

的一部分
<img class="aktion_tertial_wunsch_setzen " data-pj_traineeship_tertial_id="166037"
      data-pj_general_traineeship_id="8487" data-changetype="24"  
      src="images/wunsch_setzen_button.svg" alt="+" title="Wunsch">
<td class="hinweise_leer  verfuegbar  buchungsphase "> </td>
<td class=" tertial_verfuegbarkeit verfuegbar  buchungsphase  ">1/3</td>

提前致谢

你试过在xpath中使用position()方法吗? 例如:

// xpath using position() targeting the first element starts-with(text(),'1/'
res= browser.find_elements_by_xpath("//*[starts-with(text(),'1/')][position()=1]")
res[0].click()