Selenium 无法点击按钮元素

时间:2021-04-02 15:05:07

标签: python html selenium selenium-webdriver automation

我在 python 中使用 selenium,我试图单击一个按钮,但它似乎不起作用。这是 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 和 class 单击按钮,但没有任何效果。它甚至也不会给我一个错误。 我对每个答案都很满意!

1 个答案:

答案 0 :(得分:0)

尝试通过文本找到您的按钮: 尝试 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()