AttributeError: 'list' object has no attribute 'click' using Selenium and Python

前端 未结 4 1148
无人共我
无人共我 2020-12-19 13:12

I\'d like to click the button \'Annual\' at a page that is by default set on \'Quarterly\'. There are two links that are basically called the same, except that one has

4条回答
  •  心在旅途
    2020-12-19 13:29

    As per the documentation find_elements_by_xpath(xpath) returns a List with elements if any was found or else an empty list if not. Python's List have no click() method associated with it. Instead find_element_by_xpath(xpath) method have the click() method associated with it. So you have to use find_element_by_xpath(xpath) method inducing a waiter through WebDriverWait inconjunction with expected_conditions set as element_to_be_clickable(locator) as follows:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='newBtn toggleButton LightGray' and @data-type='rf-type-button']"))).click()
    

    Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    

提交回复
热议问题