Search code examples
pythonwebtypeerrorquora

TypeError: 'WebElement' object is not callable


hello i have this little peace of code that will check if a link is good but i can't run it.

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()

cause when i run it i get the error:

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

Solution

  • 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()