Python Scope Issue: Runtime Error when running python script with selenium library imported

Hi community,
I’m trying to run a python script to webscrape, and I’m using the Selenium library, but I’m getting a particular error message that says “cannot import name ‘webdriver’ from ‘selenium’”
Below is a more comprehensive version of the error message.
NOTE: I copied this error from my PC’s Event Viewer window.

Application: UiPath.Python.Host.exe CoreCLR Version: 6.0.3024.21525 .NET Version: 6.0.30 Description: The process was terminated due to an unhandled exception. Exception Info: Python.Runtime.PythonException: ImportError : cannot import name 'webdriver' from 'selenium' (C:\Python\Python37\lib\site-packages\selenium\__init__.py) [' File "none", line 4, in goto_github_and_download_file\n'] at Python.Runtime.PyObject.Invoke(PyObject[] args) at Python.Runtime.PyObject.InvokeMethod(String name, PyObject[] args)
However, the other python methods without the selenium dependency work perfectly. The error is just peculiar to the method that uses the selenium library.

Your help will be greatly appreciated in fixing this issue. I’m available to provide further details if required.

@Babatunde_Omotayo

Few things here

  1. Only this import is not working or any import is not working?
  2. Did you happen to provide the library path?
  3. And is the target package installed in same instance of python which is invoked from UiPath?

Cheers

What do you get when pip show selenium?

Thank you for your response

  1. Yeah, only the selenium import is not working. All other imports work perfectly
  2. Yeah, I provided the path the correct python path
  3. And yes the package is installed in the same python instance that is invoked into UiPath

Below is a description of the selenium package installed and the path
C:\Python\Python37>C:\Python\Python37\python.exe -m pip show selenium
Name: selenium
Version: 4.11.2
Summary: None
Home-page: https://www.selenium.dev
Author: None
Author-email: None
License: Apache 2.0
Location: c:\python\python37\lib\site-packages
Requires: trio-websocket, trio, certifi, urllib3
Required-by:

Below is a screenshot of where I defined the python path in my workflow
image

Thank you…I look forward to your response

image
This is what i get

@Babatunde_Omotayo

Try giving the lib path as well in the python field

Cheers

I hope this is what you mean
image

Also, below is the breakkdown of the folder structure

  • Python
    • Python37
      • Lib
        • site_packages
          • selenium
            • webdriver
              • common
              • chrome
                • webdriver.py
              • edge
                • webdriver.py

@Babatunde_Omotayo

I meant give the python library path in the python scope library path argument

cheers

Okay, I did that already

@Babatunde_Omotayo

the field above it library path…give the lib folder path

cheers

Okay…Like it is shown below right?

1 Like

Hello @Anil_G
Just checking in please.
I’ve implemented your solution but still getting the same error

I look forward to your response.
Thanks

First things first - the library path should be provided as per this documentation example:

Apart from that, I tested it just now with Python 3.12 and it makes this import correctly:

And therefore we would need more info:

  • first, whether this script works for you:
from selenium import webdriver
def dummy_func():
    return "text"