【问题标题】:How to click html 'button class' using selenium at python如何在python中使用硒单击html“按钮类”
【发布时间】:2019-02-26 05:15:44
【问题描述】:

我想使用 python selenium 单击按钮,但没有这样做。如何使用代码点击“나중에 하기”?我试过 driver.find_element_by_link_text 但没有用...请帮助

elem = driver.find_element_by_link_text('나중에 하기')
elem.send_keys(Keys.RETURN)

button class="aOOlW  bIiDR  " tabindex="0">설정</button"
button class="aOOlW   HoLwm " tabindex="0">나중에 하기</button"

【问题讨论】:

  • 请显示更多您的代码,如果可能,请通过edit 和url 使用sn-p 工具包含相关的html。

标签: python selenium button


【解决方案1】:

find_element_by_link_text 仅适用于 &lt;a&gt; 标记。尝试通过xpath 定位元素

driver.find_element_by_xpath('//button[.="나중에 하기"]').click()

或者使用类代替文本定位

driver.find_element_by_class_name('HoLwm').click()

【讨论】:

  • 完美!非常感谢!
【解决方案2】:

您可以尝试等待元素可点击,然后为标签和类组合 CSS 选择器

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.HoLwm"))).click()

进口

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-12
    • 2023-03-05
    • 2021-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多