[英]Selenium - Python - find_element_by_link_text not sure what's wrong
This is my first time with both Python and Selenium, and I'm trying to select and click on an element of the navigation bar of this website - stockfetcher.com 这是我第一次使用Python和Selenium,并且我试图选择并单击此网站的导航栏上的一个元素-stockfetcher.com
I would like to click on the MyFilters tab on the navigation bar. 我想单击导航栏上的MyFilters选项卡。 After inspecting the element, I see that the HTML code for that element is
检查元素之后,我看到该元素的HTML代码是
<a href="/myfilters"> "MyFilters " <span class="tab-pill"></span> </a>
And here's what I trying to do 这就是我想要做的
driver.find_element_by_link_text("MyFilters ").click()
And I get this error 我得到这个错误
AttributeError: 'NoneType' object has no attribute 'click'
Any idea what's wrong? 知道有什么问题吗? Most examples I watched online did not have "" around whatever is inside the tag.
我在网上观看的大多数示例在标记内的内容周围都没有“”。 Is that what's messing me up?
那是什么让我烦恼?
Link text is sometimes very picky about what you send to it, and I have found that you have to match what the actual link is showing, and not the value following href. 链接文本有时对您发送给它的内容非常挑剔,我发现您必须匹配实际链接显示的内容,而不是href后面的值。 Since the site shows
MyFilters
, try doing this instead: 由于该网站显示
MyFilters
,因此请尝试执行以下操作:
driver.find_element_by_link_text('MyFilters').click()
Without the space after Filters . 过滤器后没有空格。 I tested on my side and it seems to work.
我站在一边测试,它似乎有效。
Also, the error does not match what you have given as an example, it would throw NoSuchElementException
, before it would throw that NoneType
has no click() event. 此外,该错误与您作为示例给出的错误也不匹配,它将引发
NoSuchElementException
,然后引发NoneType
没有click()事件。 Either way the above should work for you. 无论哪种方式,以上都应该为您工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.