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

前端 未结 4 1150
无人共我
无人共我 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:39

    Notice that find_elements_by_xpath is plural it returns a list of elements. Not just one. The list can contain none, exactly one, or more elements.

    You can for example click the first match with:

    driver.find_elements_by_xpath("/html/body/div[5]/section/div[8]/div[1]/a[1]")[0].click()

    or iterate through the list and click all these elements, or you can use the find_element_by_xpath (which returns a single element, if it can be found):

    driver.find_element_by_xpath("/html/body/div[5]/section/div[8]/div[1]/a[1]").click()

提交回复
热议问题