Python 如何通过类名找到href并单击selenium
我正在使用Selenium和python制作一个蜘蛛 网页的一部分是这样的:Python 如何通过类名找到href并单击selenium,python,selenium,href,Python,Selenium,Href,我正在使用Selenium和python制作一个蜘蛛 网页的一部分是这样的: <a href="http://www.example.html" target="_blank" class="_j_search_link">text - <span class="sr-keyword">name</span> text</a> 目标不是None,但似乎无法单击它,因为在target.click()之后,什么也没有发生。 另外,我读到了这个问题:
<a href="http://www.example.html" target="_blank" class="_j_search_link">text - <span class="sr-keyword">name</span> text</a>
目标不是None
,但似乎无法单击它,因为在target.click()之后,什么也没有发生。
另外,我读到了这个问题:
但这对我没有帮助,因为在我的例子中,有一个
,而不仅仅是一个简单的文本Google
你可以用class\u j\u search\u link
查找包含文本Wat Chedi Luang
的元素
driver.find_element_by_xpath('//a[@class="_j_search_link" and contains(., "Wat Chedi Luang")]')
您可以使用类\u j\u search\u link
查找包含文本Wat Chedi Luang
driver.find_element_by_xpath('//a[@class="_j_search_link" and contains(., "Wat Chedi Luang")]')
我认为你没有找到正确的元素。使用CSS或Xpath以该元素为目标,然后单击它,如:
//a[@class='_j_search_link']
或
我认为你没有找到正确的元素。使用CSS或Xpath以该元素为目标,然后单击它,如:
//a[@class='_j_search_link']
或
点击对其他元素有效吗?@HarshithThota好吧,它对按钮有效。你说目标不是零。这是什么?@harshithhota,因为我已经打印了:print(target)
。它显示:
@HarshithThota-hmm。。。。似乎存在许多\u j\u搜索链接
。等一下……点击对其他元素有用吗?@HarshithThota嗯,它对按钮有效。你说目标不是无。这是什么?@harshithhota,因为我已经打印了:print(target)
。它显示:
@HarshithThota-hmm。。。。似乎存在许多\u j\u搜索链接
。请稍等……移动延迟再次妨碍:/mobile lag再次妨碍:/
//a[@class='_j_search_link']/span[@class='sr-keyword']