AttributeError: 'list' object has no attribute 'click' - Selenium Webdriver

后端 未结 8 703
暗喜
暗喜 2020-11-27 22:42

I am trying to use click command in Selenium webdriver using python. But I am getting the below error. Can some one help me?

Traceback (most recent call last         


        
8条回答
  •  孤街浪徒
    2020-11-27 22:54

    Refers to the locating elements documentation, here is an explanation of find_elements_*:

    To find multiple elements (these methods will return a list)

    So, to access particular element, using an index like this:

    #first element
    driver.find_elements_by_xpath("xpath")[0].click()
    

    Or you can use a loop to access all elements in the list:

    #assumed to click the checkbox
    chks = driver.find_elements_by_xpath("xpath")
    for chk in chks:
        chk.click()
    

提交回复
热议问题