3

Is there a way to install selenium webdriver as a python project dependence.

I need this in such a way, so when this project goes to a os, that doesn't have selenium webdriver installed not to be an issue for this project to run properly on that os.

Thank you in advance.

PS: Please take a look at my own answer to this question.

Stefan

2
  • Since webdriver is not a Python package, it is impossible for you to add that as dependence. Also the webdriver is provided by third party so you will need to ask the users to download it. Commented Mar 27, 2017 at 7:09
  • OK, then lets say if that os has selenium installed as overall (it can be accessed by maven project) but doesn't have the python part. Is there a way to add this python part as a dependency to my project as it can be added to maven? Commented Mar 27, 2017 at 8:28

2 Answers 2

2

This is how I have done for all my projects.

  • Create a text file which has all the project dependencies mentioned. make sure you mentioned version as well. Example: requirement.txt

    • pytest==2.9.1
    • selenium==2.35.1
  • Create a Shell script or batch file which, creates a new virtual environment, installs all the dependencies and run the tests.
Sign up to request clarification or add additional context in comments.

5 Comments

this is not what OP is asking tho... OP is asking about selenium webdriver not selenium.
In my case this python project needs to be run on a windows based browser VM, that can run selenium as a java maven dependency. I gues i just need the python part of the selenium to call the main selenium execution or am I wrong?
@AlexFung requirement.txt is just an example. he can put different dependencies bases on his project requirement.
@stefan.stt doesn't matter in which environment you want to run this project. pip install works on all the environment. however, I am not sure if you can install python lib using maven.
As far as I am aware selenium is Java based. Selenium for python is using python scripts that in the end are calling the Java based selenium. So my idea is how to add those selenium python scripts to my project as project dependencies in the case that Java selenium is installed on this windows based browser VM. Or perhaps I don't understand the selenium webdriver logic.
1

I solved my problem this way:

  1. Installing pip for the current OS I am working on
  2. Installing selenium with the following command:

    pip install --install-option="--prefix=<path_to_dependencies_in_my_python_project>" -U selenium
    
  3. Import selenium module from this dependencies project folder

Also another approach is to check if the new OS has selenium installed and if not - install it via python script. The code looks something like that:

 # windows
 try:
     from selenium import webdriver
 except ModuleNotFoundError:
     os.system("pip install --install-option=\"--prefix={}\" selenium"
               .format(os.path.join(project_main_folder_path, "_depedencies")))
     from selenium import webdriver

# Linux
try:
    from selenium import webdriver
except:
    os.system("pip install selenium -t {}"
              .format(os.path.join(project_main_folder_path, "_depedencies", "Lib", "site-packages")))
    from selenium import webdriver

Take a look at the difference of the pathing - on Linux it is installed directly in the folder, while on windows it is installed in sub-folder "Lib\site-packages". Also I don't know why, but I had problems with name 'ModuleNotFoundError' is not defined.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.