Selenium不能单击按钮元素

2024-10-01 09:16:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我将selenium与python结合使用,并尝试单击一个按钮,但它似乎不起作用。以下是html部分:

<div class="nmMym">
   <button class="sqdOP yWX7d     _8A5w5    " type="button">
      <div class="                     Igw0E     IwRSH      eGOV_         _4EzTm                                                                                              qJPeX                ">
         <div class="_7UhW9   xLCgt       qyrsm KV-D4          uL8Hv         ">Annehmen</div>
      </div>
   </button>
</div>

我已经尝试通过xpath和类单击按钮,但没有任何效果。它甚至没有给我一个错误。 我对每个答案都很满意


Tags: divhtmltypeseleniumbutton按钮classxlcgt
1条回答
网友
1楼 · 发布于 2024-10-01 09:16:28

尝试通过其文本查找您的按钮: 尝试1:

your_button= driver.find_element_by_xpath("//button/div/div[contains(text(), 'Annehmen')]")

或者,另一种方式: 尝试2:

your_button = driver.find_element_by_xpath("//button/div/div[contains(@class,'_7UhW9   xLCgt       qyrsm KV-D4          uL8Hv         ')]")  

尝试仅使用以下命令来省略//button/div/尝试3次

your_button = driver.find_element_by_xpath("//div[contains(text(), 'Annehmen')]")

尝试4: 另一种选择:

your_button = driver.find_element_by_xpath("//button[contains(@class,'sqdOP yWX7d     _8A5w5    ')]") 

试试5(CSS)

driver.find_element_by_css_selector(".sqdOP .yWX7d     ._8A5w5    ")

最后加上

your_button.click()

相关问题 更多 >