[英]How to click on a href link by using python scripts and selenium?
我正在尝试让Selenium单击特定的href,例如
<a href="publications.html">Publications</a>
我试着做
driver.find_element_by_link_text('Publications.html').click()
但这给了我错误:
AttributeError:'NoneType'对象没有属性'click'。
有什么建议么?
.find_element_by_link_text()
通过A
标签内的文本查找A
标签,例如
<a href="publications.html">Publications</a>
您可以使用以下标签找到此标签
driver.find_element_by_link_text("Publications")
但是...如果要通过href查找A
标签,则需要使用其他方法。
driver.find_element_by_css_selector("a[href='publications.html']")
这是一个CSS选择器。 您可以在下面的链接中找到有关它们的更多信息。
更改
find_element_by_link_text('Publications.html')
至
find_element_by_link_text('Publications')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.