【问题标题】:Selenium click on button硒单击按钮
【发布时间】:2021-12-08 01:27:59
【问题描述】:

网页上有按钮,具体代码如下:

<button onclick="getListRating(1); return false;" class="button is-gray pagination__more">Open</button>

需要通过使用 selenium lib 进行点击 - 首先我尝试查找为“css_celector”,但没有成功:

allm=driver.find_element(By.CSS_SELECTOR, 'button is-gray pagination__more')  # Find button
allm.click() # Click!

我需要使用什么查找类来单击此按钮?

【问题讨论】:

  • 请编辑问题以将其限制为具有足够详细信息的特定问题,以确定适当的答案。

标签: python html css selenium


【解决方案1】:

我会通过 onclick attr 找到按钮。这是使用 xpath 的解决方案。

button = driver.find_element_by_xpath('//button[@onclick="getListRating(1); return false;"]')
button.click()

【讨论】:

    猜你喜欢
    • 2020-04-15
    • 1970-01-01
    • 2018-11-02
    • 1970-01-01
    • 2023-01-11
    • 2020-12-05
    • 2016-05-29
    • 1970-01-01
    • 2021-08-12
    相关资源
    最近更新 更多