Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/303.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/3/heroku/2.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 使用selenium单击按钮_Python_Html_Selenium - Fatal编程技术网

Python 使用selenium单击按钮

Python 使用selenium单击按钮,python,html,selenium,Python,Html,Selenium,用于单击具有以下HTML代码的按钮: <a href="javascript:submitPage('V','All Notes','');" class="viewFilter">All Notes</a> 我真的不确定这里的问题是什么——对于这个网页上的所有其他按钮按下——selenium一直在正常工作。我还可以尝试其他什么方法 all_notes = WebDriverWait(driver,10).until(EC.pre

用于单击具有以下HTML代码的按钮:

<a href="javascript:submitPage('V','All Notes','');" class="viewFilter">All Notes</a>
我真的不确定这里的问题是什么——对于这个网页上的所有其他按钮按下——selenium一直在正常工作。我还可以尝试其他什么方法

all_notes = WebDriverWait(driver,10).until(EC.presence_of_element_located(
    (By.XPATH, '//*[@href="javascript:submitPage(\'V\',\'All Notes\',\'\');"]'))).click()
转义单引号

转义单引号试试这个Xpath

//a[@class='viewFilter' and contains(text(), 'All Notes')]
这样做的目的是验证类是否为viewFilter,并且由于类可以多次出现,因此还可以确保链接文本都是Notes。

尝试此Xpath

//a[@class='viewFilter' and contains(text(), 'All Notes')]

这样做的目的是验证类是否为viewFilter,并且由于类可以多次出现,因此还可以确保链接文本都是Notes。

您是否已经使用chrome开发工具测试您的XPath?是的,我的chrome XPath已经在代码中的上一次按钮点击上工作,没有问题您是否已经使用chrome开发工具要测试你的XPath吗?是的,我的chrome XPath已经在代码前面的按钮点击上运行过,没有问题,但只是尝试过,不幸的是,与之前相同的错误消息:“TimeoutException:message:”@Ossz更新了答案您应该对href值使用双引号,并用单引号将其括起来quotes@Ossz你试过新代码吗?刚试过,效果很好-非常感谢!谢谢,但不幸的是,刚刚尝试了与之前相同的错误消息:“TimeoutException:message:”@Ossz更新了答案您应该对href值使用双引号,并用单引号括起来quotes@Ossz你试过新代码吗?刚试过,效果很好-非常感谢!