[英]Selenium cant click button element
i am using selenium with python and i am trying to click a button but it doesn't seem to work.我正在使用 selenium 和 python 并且我试图单击一个按钮,但它似乎不起作用。 Here's the html part:这是 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>
I already tried clicking the button by xpath and class, nothing worked.我已经尝试点击 xpath 和 class 的按钮,但没有任何效果。 It also doesnt even give me an error.它甚至没有给我一个错误。 I'm happy about every answer!我对每一个答案都很满意!
Try to find you button by its text: Try 1:尝试通过其文本找到您的按钮:尝试 1:
your_button= driver.find_element_by_xpath("//button/div/div[contains(text(), 'Annehmen')]")
Or, another way: Try 2:或者,另一种方式:尝试2:
your_button = driver.find_element_by_xpath("//button/div/div[contains(@class,'_7UhW9 xLCgt qyrsm KV-D4 uL8Hv ')]")
Try to omit //button/div/
by using just: Try 3尝试省略//button/div/
仅使用:尝试 3
your_button = driver.find_element_by_xpath("//div[contains(text(), 'Annehmen')]")
Try 4: Another option:尝试4:另一种选择:
your_button = driver.find_element_by_xpath("//button[contains(@class,'sqdOP yWX7d _8A5w5 ')]")
Try 5 (CSS)尝试 5 (CSS)
driver.find_element_by_css_selector(".sqdOP .yWX7d ._8A5w5 ")
In the end add最后加上
your_button.click()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.