Using Selenium in Python to click through all elements with the same class name

前端 未结 1 1124
时光说笑
时光说笑 2021-02-06 15:20

I am trying to click on all of the \"like\" buttons on a webpage. I know how to click on one of them, but I\'d like to be able to click them all. They have the same class name

相关标签:
1条回答
  • 2021-02-06 15:58

    This is unfortunate, you got two halves of the whole, you cannot find multiple elements by id as ID is unique to a single element.

    so combine the iterative method you use with id and the find by elements with classes to get:

    like = browser.find_elements_by_class_name('like_picto_unselected')
    for x in range(0,len(like)):
        if like[x].is_displayed():
            like[x].click()
    

    I strongly suspect this will work for you. Please tell me if not.

    0 讨论(0)
提交回复
热议问题