I'm trying to execute selenium script. I have defined the wait
variable, but still code is returning the error.
This is my wait variable,
wait = WebDriverWait(driver, 100)
error:
Traceback (most recent call last):
File "main.py", line 160, in <module>
tenant = wait.until(EC.visibility_of_element_located((By.NAME, "tenantsearch")))
NameError: name 'wait' is not defined
CodePudding user response:
Yes, you defined it, but did you import it first?
from selenium.webdriver.support.ui import WebDriverWait
Also, did you import it / define it in the file where you are calling it from?
CodePudding user response:
This error message...
NameError: name 'wait' is not defined
...implies that the variable you are trying to use i.e. wait
is yet to be defined.
Solution
Presumably the wait
variable seems to be a type of WebDriverWait. So you have to define it first as:
wait = WebDriverWait(driver, 20)
Then you can use the following line of code:
tenant = wait.until(EC.visibility_of_element_located((By.NAME, "tenantsearch")))
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Note: As you are using WebDriverWait remember to remove all the instances of
implicitly_wait()
as mixing implicit and explicit waits can cause unpredictable wait times. For example setting an implicit wait of 10 seconds and an explicit wait of 15 seconds, could cause a timeout to occur after 20 seconds.