Python selenium-我如何能够使用特定值单击屏幕上的所有按钮

Python selenium-我如何能够使用特定值单击屏幕上的所有按钮,python,selenium,selenium-chromedriver,Python,Selenium,Selenium Chromedriver,所以现在我正尝试使用selenium来自动化一个签出过程。但是,有三个相同的按钮,我想按下它们。还有什么我可以做的吗 所有三个按钮都具有相同的类 expandButton = driver.find_element_by_xpath("//div[@class='expand-collapse']") expandButton.click() 您可以使用该函数查找xpath指定的所有元素: expandButtons = driver.find_elements_by_xpath("

所以现在我正尝试使用selenium来自动化一个签出过程。但是,有三个相同的按钮,我想按下它们。还有什么我可以做的吗

所有三个按钮都具有相同的类

expandButton = driver.find_element_by_xpath("//div[@class='expand-collapse']")
expandButton.click()

您可以使用该函数查找xpath指定的所有元素:

expandButtons = driver.find_elements_by_xpath("//div[@class='expand-collapse']")
这将在
expandButtons
中存储与xpath匹配的所有元素的列表。 然后,您可以通过以下方式对其进行循环:

for button in expandButtons:
    button.click()
这将单击找到的所有按钮