在Selenium Python中找到所有可能的按钮元素
我正在尝试从网站上获取所有按钮,但是似乎硒语法已经更改,而没有更新文档。我正在尝试从网站上获取按下的按钮:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
url = 'https://www.programiz.com/python-programming'
driver.get(url)
buttons = driver.find_element(by=By.TAG_NAME("button"))
但是我会收到以下错误:
TypeError: 'str' object is not callable
如前所述,这些文档仍然说使用 find_element_by_tag_name
被贬低了。有人可以帮忙吗?谢谢
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
find_element_by _*
命令是 efferciated 现在。要查找所有
< button>
元素,您可以使用以下 定位器策略 :使用 tag_name :
使用 css_selector :
使用 xpath :
find_element_by_*
commands are depreciated now.To find all the
<button>
elements you can use the following locator strategies:Using tag_name:
Using css_selector:
Using xpath:
问题是tag_name,它只是常数而不是可呼叫的方法,
文档的新用法应为:
在此处检查docs
Problem is with TAG_NAME it is just constant not a callable method,
new usage by docs should be:
Checked docs here https://www.selenium.dev/selenium/docs/api/py/index.html#example-1