Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.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如果按钮名为save,如何单击按钮_Python_Python 3.x_Selenium Webdriver - Fatal编程技术网

Selenium python如果按钮名为save,如何单击按钮

Selenium python如果按钮名为save,如何单击按钮,python,python-3.x,selenium-webdriver,Python,Python 3.x,Selenium Webdriver,我有下面的html <button>save</button> <button>Cancel</button> <button>View</button> 如果巴顿有名字的话,我就能做到。但是,如果按钮没有名称(如我的示例所示),我如何单击它?如果按钮没有名称,则如下所示: button = driver.find_element_by_xpath( "(//button[contains

我有下面的html

<button>save</button>
<button>Cancel</button>
<button>View</button>

如果巴顿有名字的话,我就能做到。但是,如果按钮没有名称(如我的示例所示),我如何单击它?

如果按钮没有名称,则如下所示:

button = driver.find_element_by_xpath(
            "(//button[contains(@name, '')])")

通过XPATH获取按钮txt

button = driver.find_element(By.XPATH, '//button[text()="save"]')

button.click()

有关更多详细信息

我想单击“保存”按钮,共有3个按钮。每个按钮都没有名称属性。
button = driver.find_element(By.XPATH, '//button[text()="save"]')

button.click()