美文网首页
Selenium 之 报错AttributeError: 'li

Selenium 之 报错AttributeError: 'li

作者: 嗯哼曼 | 来源:发表于2020-07-08 20:40 被阅读0次

    py+selenium 报错
    AttributeError: 'list' object has no attribute 'click'

    报错截图

    解决方法1:
    driver.find_elements_by_xpath
    改为
    driver.find_element_by_xpath

    解决方法2:
    element = wd.find_elements_by_class_name('search-btn');
    改为
    element = wd.find_elements_by_class_name('search-btn')[0];

    解析:
    因为elements表示的是所有满足这个定位的总和,返回的是一个list,所以报错说list没有click属性。而element返回的是第一个符合定位的元素。
    也就是说:
    driver.find_elements_xxxx(xxx)[0] ==== driver.find_element_xxxx(xxxx)

    相关文章

      网友评论

          本文标题:Selenium 之 报错AttributeError: 'li

          本文链接:https://www.haomeiwen.com/subject/wtuhcktx.html