Selenium/Python-如何单击onclick()按钮



我试图在python上找到硒并点击一个加号按钮,但由于任何原因,我都会得到一个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代码。一开始看起来一切都应该正常。所以浏览器窗口打开,网页被加载,但我收到了上面提到的这个错误。

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()

最新更新