0

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!!

2
  • Question already answered here. stackoverflow.com/questions/44226576/… Commented Feb 27, 2019 at 9:25
  • tried someBeingBuilt = (logInFile.browser.find_element_by_xpath("//*[name()='zeit']")) didn't work out. I found out though that lambda works. Commented Feb 27, 2019 at 9:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.