Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/278.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
如何使用Selenium和Python根据html定位带有文本作为注释的按钮?_Python_Selenium_Xpath_Css Selectors_Webdriver - Fatal编程技术网

如何使用Selenium和Python根据html定位带有文本作为注释的按钮?

如何使用Selenium和Python根据html定位带有文本作为注释的按钮?,python,selenium,xpath,css-selectors,webdriver,Python,Selenium,Xpath,Css Selectors,Webdriver,我在chrome扩展中使用Xpath助手来查找python编程的Xpath。我已经阅读了文档,但是有更好的指南吗 HTML格式如下: <form class="addComment expand" data-id="9644797"> <img src="https://ctl.s6img.com/society6/img/g2taHIrokQ01R_67jS8ulaWI2wk/h_150,w_150/users/avatar/~artwork/s6-original-

我在chrome扩展中使用Xpath助手来查找python编程的Xpath。我已经阅读了文档,但是有更好的指南吗

HTML格式如下:

<form class="addComment expand" data-id="9644797">
    <img src="https://ctl.s6img.com/society6/img/g2taHIrokQ01R_67jS8ulaWI2wk/h_150,w_150/users/avatar/~artwork/s6-original-art-uploads/society6/uploads/u/sul97/avatar_asset/d837ee10016843a3bba9ae3310cc338d" width="25" height="25">
    <textarea placeholder="Add a comment..." data-button="9644797"></textarea>
    <button id="b9644797">Comment</button>
</form>
xpath应该是:

//button[text()='Comment']  
然而,您应该引入webdriver,等待您的代码更加稳定


.
click()
method返回void。因此,调用click方法并将其存储在变量中没有任何意义。

“html示例”。。。不,这不是一个HTML示例。。。共享HTML,而不是xpath在此处添加了HTML示例为什么需要复杂的xpath?为什么不直接使用按钮的id呢
//按钮[@id='b9644797']
@BryanOakley:因为id是随机生成的。因此,我们不能依赖此id。您的
也是webdriver等待与时间相同。sleep()?time.sleep()是webdriverwait的极端情况。有关更多详细信息,请参阅此链接。
//button[text()='Comment']