Pycharm is running script headless successfully but terminal throwing error

Viewed 141

Hello all,

options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
dr = webdriver.Chrome(ChromeDriverManager().install(), options=options)
dr.get("url")

cWait = WebDriverWait(dr, 5)
usernameField = cWait.until(EC.presence_of_element_located((By.ID, "txtUserID")))

while running the above set of lines of code, when i click on pycharm run for this python file, it works in headless in good way but when I use terminal and write code something like

python main.py

the console gives this output

====== WebDriver manager ======
Current google-chrome version is 92.0.4515
Get LATEST driver version for 92.0.4515
Driver [C:\Users\bc62700\.wdm\drivers\chromedriver\win32\92.0.4515.107\chromedriver.exe] found in cache

DevTools listening on ws://127.0.0.1:53298/devtools/browser/b967343c-b07a-43a3-8d1f-d8b41e62e50d
[0906/071237.616:INFO:CONSOLE(19)] "Uncaught TypeError: Cannot read property 'txtUserID' of undefined", source: URL (19)

It is working absolutely fine with pycharm run button, but not with terminal please help as because of this reason I am not able to make this as schedular event.

1 Answers

When you run it from within pycharm, it is using a specific python, which may be different from your system's default python. Check the run configuration in pycharm and see what the path is to the python version it is using, and try to execute it using the full path to that python, i.e. instead of python main.py it would be something like /path/to/your/project/venv/bin/python /path/to/your/project/main.py

If that's not it, try giving us a more complete explanation of your situation, so that someone can try to reproduce what's happening and investigate further.

Related