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

后端 未结 8 648
暗喜
暗喜 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:44

    Thanks for helping out. I found the answer for myself. Idea given by "Dan Niero"

    The problem is, I am using driver.find_element[s] instead of driver.find_element. So one s makes difference and calling a wrong method. In fact I am following the eclipse autocomplete :(. Obviously driver.find_elements_by_link_text returns list so If I send click event it wont understand.

    Thanks for helping and sorry for my bad question

    -Vikram

    0 讨论(0)
  • 2020-11-27 22:46

    I found below solution I was using appiumrobotlibaray version 1.5 where

    @{elemet}    get webelements     ${elemets}
    click element  @{elemet}[1]
    

    this code throw "AttributeError: 'list' object has no attribute 'click' error downgrade appium library to previous version. 1.4.6 and this is working in my case.

    0 讨论(0)
  • 2020-11-27 22:47

    if the attribute of "MISCQA Misc Tests" only has one,You can try to change elements into element in this code 'driver.find_elements_by_link_text("MISCQA Misc Tests")' Hope the problem will be fix

    0 讨论(0)
  • 2020-11-27 22:53

    if you want single element so u can use:

    driver.find_element_by_link_text("MISCQA Misc Tests")
    

    or if you want whole list, then:

    for x in self.driver.find_elements_by_link_text("MISCQA Misc Tests"):
        link = webdriver.ActionChains(self.driver).move_to_element(x).click(x).perform()
    
    0 讨论(0)
  • 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()
    
    0 讨论(0)
  • 2020-11-27 22:59

    The statement driver.find_elements_by_link_text("MISCQA Misc Tests") returns a list of WebElement some of which might not be clickable.

    So you will have to loop through the list of WebElement's returned and then click on those elements which are clickable.

    You can check if a WebElement is clickable or not by using the isClickable() function.

    I have not posted the code because I do not know Python. Hope this helps you.

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