gpt4 book ai didi

python - 使用 Python 和 Selenium 按文本单击按钮

转载 作者:太空狗 更新时间:2023-10-29 20:13:45 24 4
gpt4 key购买 nike

是否可以通过 Selenium 来单击具有相同文本的多个按钮?

Text = Unlock this result here

最佳答案

您可以通过文本找到所有按钮,然后在for 循环中为每个按钮执行click() 方法。

使用此 SO answer它会是这样的:

buttons = driver.find_elements_by_xpath("//*[contains(text(), 'My Button')]")

for btn in buttons:
btn.click()

我也推荐你看看Splinter这是一个很好的 Selenium 包装器。

Splinter is an abstraction layer on top of existing browser automation tools such as Selenium, PhantomJS and zope.testbrowser. It has a high-level API that makes it easy to write automated tests of web applications.

关于python - 使用 Python 和 Selenium 按文本单击按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35470171/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com