【问题标题】:'NoneType' object is not callable error while attempting to click on an element returned with BeautifulSoup using Selenium尝试使用 Selenium 单击 BeautifulSoup 返回的元素时出现“NoneType”对象不可调用错误
【发布时间】:2021-03-31 21:15:38
【问题描述】:

我想在 selenium 中使用 click() 方法单击以 beautifulsoup 为目标的元素,但显示此错误:

'NoneType' object is not callable

我的代码示例:

from selenium import webdriver
from bs4 import BeautifulSoup
tabs = deals_tabs.find_all('div',{'class':'FilterSort__filter___36MvO'})
tabs.pop(0)
for tab in tabs:
    category = tab.text
    tab.click()

【问题讨论】:

标签: selenium selenium-webdriver beautifulsoup webdriver click


【解决方案1】:

findall()

findall() 找到所有匹配项并将它们作为字符串列表返回,每个字符串代表一个匹配项。

所以tabs字符串列表 以及tab

但是click() 是一个WebElement 方法,不能在字符串 上调用。因此您会看到错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-11
    • 2016-10-10
    • 1970-01-01
    • 2013-12-13
    • 1970-01-01
    相关资源
    最近更新 更多