Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何通过类名找到href并单击selenium_Python_Selenium_Href - Fatal编程技术网

Python 如何通过类名找到href并单击selenium

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()之后,什么也没有发生。 另外,我读到了这个问题:

我正在使用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()之后,什么也没有发生。

另外,我读到了这个问题:

但这对我没有帮助,因为在我的例子中,有一个
,而不仅仅是一个简单的文本
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']