[英]Selenium/Python - How to click onclick() button
I am trying to find and click with selenium on python a little plus-button but for any reason I a get a TypeError
我试图在 python 上找到并单击 selenium 一个小加号按钮,但出于任何原因我得到一个
TypeError
TypeError: 'str' object is not callable
This is the link https://meshb.nlm.nih.gov/treeView and I try to find and click the following codesnippet from the html.这是链接https://meshb.nlm.nih.gov/treeView ,我尝试从 html 中找到并单击以下代码片段。
<i id="plus_Anatomy" onclick="openTree(this)" class="fa fa-plus-circle treeCollapseExpand fakeLink"></i>
This is my python code so far.到目前为止,这是我的 python 代码。 At first it looks like everything should work.
起初看起来一切都应该工作。 So browser windows opens and the webpage is loaded, but then I get this error mentioned above.
所以浏览器 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)
The bigger goal is to click on all the buttons and scrap the complete html in the end.更大的目标是点击所有按钮并最终废弃完整的 html。 can anybody please help me?
有人可以帮我吗? What am I doing wrong?
我究竟做错了什么?
You have a syntax error.你有一个语法错误。
Instead of代替
plus = driver.find_element(By.CLASS_NAME('fakeLink'))
Try尝试
plus = driver.find_element(By.CLASS_NAME, 'fakeLink')
Or even甚至
driver.find_element(By.CLASS_NAME, 'fakeLink').click()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.