0
votes

I am using the following code.

import pytest
import time
import json
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
#login
driver = webdriver.Chrome()
driver.get("url")
#time.sleep(10)
driver.set_window_size(920, 680)
driver.find_element(By.ID, "loginUserName").send_keys("xx")
driver.find_element(By.ID, "loginPassword").send_keys("yy")
driver.find_element(By.ID, "loginButton").click()

It is working fine for me and i'm not included any path and set property for chrome-extension. If i share this program,the opposite person is getting the following error and they have chromedriver.exe in python folder and in that same folder they created this python file

Traceback (most recent call last): File "C:\Users\1025043\AppData\Local\Programs\Python\Python37-32\anu\1.py", line 8, in driver = webdriver.Chrome(chrome_driver_path) NameError: name 'chrome_driver_path' is not defined

In my path i am having,

['', 'C:\Users\1024983\AppData\Local\Programs\Python\Python37\python37.zip', 'C:\Users\1024983\AppData\Local\Programs\Python\Python37\DLLs', 'C:\Users\1024983\AppData\Local\Programs\Python\Python37\lib', 'C:\Users\1024983\AppData\Local\Programs\Python\Python37', 'C:\Users\1024983\AppData\Local\Programs\Python\Python37\lib\site-packages', 'C:\Users\1024983\AppData\Local\Programs\Python\Python37\lib\site-packages\win32', 'C:\Users\1024983\AppData\Local\Programs\Python\Python37\lib\site-packages\win32\lib', 'C:\Users\1024983\AppData\Local\Programs\Python\Python37\lib\site-packages\Pythonwin']

What is the reason for this.?

Note: I am using Windows 10, Python 3.7.4 ,selenium 3.141.0 ,Chrome Version 78.0.3904.108(opposite person also using this version only)

1
chromedriver.exe needs to be in the path, it is in your computer so it works. - Guy
In opposite person's system also they have exe in python folder and in that same folder they created .py file.. - Divya Mani
So the code itself is running from different locations, or you added it to the system PATH manually. To avoid such problem add the chromedriver to the project and include relative path to it. - Guy
nope i am not included in environment variable and project home also - Divya Mani

1 Answers

0
votes

The chromedriver.exe should be included in the executable PATH. Download the chromedriver.exe and add this to the code as below. (add chrome driver path as it's located in your machine) or you can include in to the PATH variable in environment variables in windows 10.

E.g.

import pytest
import time
import json
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
#login
driver = webdriver.Chrome(executable_path=r'C:\chromedriver.exe')
driver.get("url")
#time.sleep(10)
driver.set_window_size(920, 680)
driver.find_element(By.ID, "loginUserName").send_keys("xx")
driver.find_element(By.ID, "loginPassword").send_keys("yy")
driver.find_element(By.ID, "loginButton").click()