EDIT: I'm sorry but I believe it's not the same question as the one the links directs me to. I try it again. My problem is the following:
I have a file called webElements.py where I defined a lot of variables containing selenium find_element_by_blabla() commands. E.g.:
class CwebElements:
someBeingBuilt = (logInFile.browser.find_element_by_xpath("//*
[@name='zeit']"))
I use these variables in another file, the main code, like this:
if webElements.CwebElements.someBeingBuilt:
print('Busy!')
So far so good. But when I now execute the main file, I get the following error immediatly (right at the beginning of the code, even before he's on the page where he should actually look for this element):
"... no such element: Unable to locate element: {"method":"xpath","selector":"//*[@name='zeit']"}"
I tried to use lambda as follows:
class CwebElements:
someBeingBuilt = lambda: (logInFile.browser.find_element_by_xpath("//*
[@name='zeit']"))
but When I do so, the program will work until it reaches the page where he sould look for this element 'Zeit' and will always print "Busy!". Also, when I write it like this:
if logInFile.browser.find_element_by_xpath("//*
[@name='zeit']"):
print('Busy!')
it actually works, so it's not a matter of wrong coding (I believe) but rather a problem of Python wanting to execute the Selenium commands, stored within the variables, right at the begining and not only when they are needed.
Hope it's clearer now. Thanks alot!!