0

I have developed a selenium automation using python to get some data. When I run counter.py file it works fine and able to get what I wanted. Proceed with packing my file using pyinstaller and again tested it works fine on same machine.

The issue here is when I take this exe and run on other computer it wouldn't run and instantly closes the cmd, was able to capture error with debug True as below stating chromedriver.exe not found.

I try creating exact same directory on second machine similar to what is stated in executable_path= and worked fine after placing my chromedriver.exe. My question is there any way I can pack these without needing chromedriver.exe at all on other machine.

counter.py

....
options = Options()
options.add_argument("--headless")
browser = webdriver.Chrome(executable_path=r"C:\Users\jasme\Desktop\project1\chromedriver.exe", options=options)
url = "https://en.wikipedia.org/wiki/Wiki"
browser.get(url)
....

counter.spec

a = Analysis(['counter.py'],
             pathex=['C:\\Users\\jasme\\Desktop\\project1'],
             binaries=[('C:\\Users\\jasme\\Desktop\\project1\\chromedriver.exe','\\selenium\\webdriver')],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          [],
          name='counter',
          debug=True,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          upx_exclude=[],
          runtime_tmpdir=None,
          console=True )

Error

[20396] LOADER: callfunction returned... 
[20396] LOADER: extracted pyimod03_importers 
[20396] LOADER: callfunction returned... 
[20396] LOADER: Installing PYZ archive with Python modules. 
[20396] LOADER: PYZ archive: PYZ-00.pyz 
[20396] LOADER: Running pyibootOl_bootstrap.py 
[20396] LOADER: Running counter.py 
Traceback (most recent call last): 
    File "site-packages\selenium\webdriver\common\service.py", line 76, in start 
    File "subprocess.py", line 800, in _init_ 
    File "subprocess.py", line 1207, in _execute_child 
FileNotFoundError: [winError 2] The system cannot find the file specified 

During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
    File "counter.py", line 35, in <module>     
    File "site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in _init_ 
    File "site-packages\selenium\webdriver\common\service.py", line 83, in start 
selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. 
Please see https://sites.google.com/a/chromium.org/chromedriver/home 

[20396] Failed to execute script counter 
[20396] LOADER: OK. 
[20396] LOADER: Cleaning up Python interpreter. 
[2264] LOADER: Back to parent (RC: -1) 2 

P.S: sorry if the title is confusing maybe someone can modify it.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
jasmeet
  • 53
  • 1
  • 10

2 Answers2

0

you don't have to create a the same directory what you can do is either place the chromedriver.exe in a folder and copy the full path

or

just place the chromedriver.exe in the same folder as the counter.py

and add this to the code.

this should work.

 browser = webdriver.Chrome(executable_path="chromedriver.exe", options=options)
i_am_deesh
  • 448
  • 3
  • 12
0

This error message...

selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. 

...implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session as it wasn't found in the path provided.


Presuming you are on system, No, you can't access the WebDriver binary stored in a network location while executing your tests. Even if you proceed with packing the executable binary using pyinstaller and execute on other systems, it won't work.

If you try to access the WebDriver binary stored in a network location to execute your tests, you will face an error as:

  • ChromeDriver:

    [SEVERE]: CreatePlatformSocket() returned an error: An invalid argument was supplied.
    
  • GeckoDriver:

    An invalid argument was supplied.
    

Reference

You can find a couple of detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Isn't the purpose of pyinstaller --onefile .spec file is to include binary together with it so other PC's wouldn't require any other file and ability to work standalone. Or I'm totally getting wrong with this? Has anyone able to do this before? – jasmeet Jan 23 '20 at 11:01
  • @jasmeet Pardon me, I don't practice with `.spec` file but I am aware about the consequences when webdriver variant is kept in shared locations. – undetected Selenium Jan 23 '20 at 11:05