使用 Python 和 Selenium 按文本单击按钮 [英] Click button by text using Python and Selenium
问题描述
是否可以使用
可以通过文本查找所有按钮,然后对for
click()方法> 循环.
使用这个 SO 答案 应该是这样的:
buttons = driver.find_elements_by_xpath("///*[contains(text(), 'My Button')]")对于按钮中的 btn:btn.click()
我还建议您查看 Splinter,这是一个很好的 Selenium 包装器.
<块引用>Splinter 是现有浏览器自动化之上的一个抽象层Selenium、PhantomJS 和 zope.testbrowser 等工具.它有一个可以轻松编写 Web 自动化测试的高级 API应用程序.
Is it possible to click multiply buttons with the same text with Selenium?
You can find all buttons by text and then execute click()
method for each button in a for
loop.
Using this SO answer it would be something like this:
buttons = driver.find_elements_by_xpath("//*[contains(text(), 'My Button')]")
for btn in buttons:
btn.click()
I also recommend you take a look at Splinter which is a nice wrapper for 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 和 Selenium 按文本单击按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!