0

I'm trying to execute selenium script. I have defined the wait variable, but still code is returning the error. My main issue is that, I'm able to run this on my machine, but when I tried in my colleagues machine. It is throwing this error. I dont know why I have given the chrome executable path. I have installed every package used in my project. Please help me

I have imported all these:

import os
import sys
os.system('pip3 install selenium')
os.system('pip3 install pandas')
os.system('pip3 install mysql-connector-python')
os.system('pip3 install webdriver_manager')
import time
#from webdriver_manager.chrome import ChromeDriverManager
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as 
EC
from selenium.webdriver.common.keys import Keys
import mysql.connector
import getpass
from mysql.connector import connect, Error
import pandas as pd
import multiprocessing as mp
import csv
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--start-maximized')
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
DRIVER_BIN = os.path.join(PROJECT_ROOT, "chromedriver")
os.system('xattr -d com.apple.quarantine chromedriver')
driver = webdriver.Chrome(executable_path=DRIVER_BIN, 
options=chrome_options)

enter image description here

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
Sai Pavan
  • 11
  • 2
  • 2
    Please show your code as text in a [mcve], not as an image. What is in lines 1-146? As shown in line 160, `wait` is highlighted, probably saying it is not defined. – OneCricketeer Jul 29 '22 at 18:07
  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jul 29 '22 at 18:41

2 Answers2

1

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?

Barry the Platipus
  • 9,594
  • 2
  • 6
  • 30
  • This is just one script. When I'm using it on my local machine the script is running fine. But when I'm running the script on my colleague's laptop. I'm getting the above error. – Sai Pavan Jul 31 '22 at 00:44
0

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.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352