TypeError: 'WebElement' object is not callable

208 views Asked by At

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
1

There are 1 answers

5
FloLie On BEST ANSWER
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()