【问题标题】:TypeError: 'WebElement' object is not callableTypeError:“WebElement”对象不可调用
【发布时间】:2021-06-07 16:23:26
【问题描述】:

你好,我有一些代码可以检查链接是否正常,但我无法运行它。

links = driver.find_elements_by_partial_link_text('')
l = links[random.randint(0, len(links)-1)]
while "profile" in l():
    print("finding new link")
    links = driver.find_elements_by_partial_link_text('')
    l = links[random.randint(0, len(links) - 1)]
l.click()

因为当我运行它时,我得到了错误:

while "profile" in l():
TypeError: 'WebElement' object is not callable

【问题讨论】:

    标签: python web typeerror quora


    【解决方案1】:
    import random
    links = driver.find_elements_by_partial_link_text('')
    l = links[random.randint(0, len(links)-1)]
    while True:
        if l.text.find("profile") >= 0:
            print("finding new link")
            links = driver.find_elements_by_partial_link_text('')
            l = links[random.randint(0, len(links) - 1)]
        else:
            break;
    l.click()
    
    

    【讨论】:

    • 如果我这样做,我会得到
    • AttributeError: 'WebElement' 对象没有属性 'find'
    • 很高兴听到。接受的答案将不胜感激:)
    • 我该怎么做?
    • 现在就知道了
    猜你喜欢
    • 2020-11-09
    • 2020-03-03
    • 2022-12-12
    • 1970-01-01
    • 2023-03-06
    • 2021-12-07
    • 1970-01-01
    • 1970-01-01
    • 2021-10-25
    相关资源
    最近更新 更多