![](/img/trans.png)
[英]How to find and click the button by "onclick" with Selenium and Python?
[英]Selenium/Python - How to click onclick() button
我试图在 python 上找到并单击 selenium 一个小加号按钮,但出于任何原因我得到一个TypeError
TypeError: 'str' object is not callable
这是链接https://meshb.nlm.nih.gov/treeView ,我尝试从 html 中找到并单击以下代码片段。
<i id="plus_Anatomy" onclick="openTree(this)" class="fa fa-plus-circle treeCollapseExpand fakeLink"></i>
到目前为止,这是我的 python 代码。 起初看起来一切都应该工作。 所以浏览器 windows 打开并加载了网页,但随后出现上述错误。
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get("https://meshb.nlm.nih.gov/treeView")
plus = driver.find_element(By.CLASS_NAME('fakeLink'))
driver.execute_script("arguments[0].click();", plus)
更大的目标是点击所有按钮并最终废弃完整的 html。 有人可以帮我吗? 我究竟做错了什么?
你有一个语法错误。
代替
plus = driver.find_element(By.CLASS_NAME('fakeLink'))
尝试
plus = driver.find_element(By.CLASS_NAME, 'fakeLink')
甚至
driver.find_element(By.CLASS_NAME, 'fakeLink').click()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.