Click button by text using Python and Selenium

前端 未结 3 2125
逝去的感伤
逝去的感伤 2021-01-04 05:30

Is it possible to click multiply buttons with the same text with Selenium?

3条回答
  •  失恋的感觉
    2021-01-04 06:17

    You can find all buttons by text and then execute click() method for each button in a for loop.

    Using this SO answer it would be something like this:

    buttons = driver.find_elements_by_xpath("//*[contains(text(), 'My Button')]")
    
    for btn in buttons:
        btn.click()
    

    I also recommend you take a look at Splinter which is a nice wrapper for Selenium.

    Splinter is an abstraction layer on top of existing browser automation tools such as Selenium, PhantomJS and zope.testbrowser. It has a high-level API that makes it easy to write automated tests of web applications.

提交回复
热议问题