Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.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_Python 3.x_Selenium_Selenium Webdriver - Fatal编程技术网

Python 在selenium中,如何定位同一列表中具有相同类但按钮上有不同文本的按钮元素?

Python 在selenium中,如何定位同一列表中具有相同类但按钮上有不同文本的按钮元素?,python,python-3.x,selenium,selenium-webdriver,Python,Python 3.x,Selenium,Selenium Webdriver,这是网站上的html代码: 基本上我想做的是找到按钮,但是所有的按钮都有相同的类 根据 您可以通过xpath找到它: from selenium.webdriver.common.by import By mytext = "special button" driver.find_element(By.XPATH, '//button[text()="{}"]'.format(mytext)) 要找到显示“特殊按钮”的按钮,只需使用xpath并获取web元素即可 WebElement but

这是网站上的html代码:

基本上我想做的是找到按钮,但是所有的按钮都有相同的类

根据

您可以通过xpath找到它:

from selenium.webdriver.common.by import By
mytext = "special button"
driver.find_element(By.XPATH, '//button[text()="{}"]'.format(mytext))

要找到显示“特殊按钮”的按钮,只需使用xpath并获取web元素即可

WebElement button = driver.findElement(By.xpath("//button[text()='Buy  $100']"));

到目前为止你试过什么?到底是什么问题?你尝试过任何东西,做过任何研究吗?谢谢,这很有效,但我想让“一些文本”成为用户输入,当我做[text()='+text']'时,它会说']'有错误。请改用字符串格式。检查更新的回答,他们更改了网站,并在html中将按钮分为不同的行。我将如何查找该按钮。