Arslan
Arslan

Reputation: 1

Selenium python code to Executable program

I am using selenium chrome webdriver with python. I have this python code and I want to convert it into an executable program. I also have to use this external file of chrome web-driver. How can I do this?

from selenium import webdriver

def function():

    global driver
    driver = webdriver.Chrome(executable_path=r"C:\Users\Administrator\Desktop\AWS\chromedriver_win32\chromedriver" )
    driver.get('https://www.google.com')
    driver.close()

function()

Upvotes: 0

Views: 423

Answers (3)

Chandella07
Chandella07

Reputation: 2117

Two ways to achieve this.

scenario 1

You can use the location of your python file. Rather hard coding path in script you can use a relative path which will remain same every time you run your script and you can always put chromedriver.exe in same path where your python file is. using below example.

    import os

    driverpath = os.path.join(os.path.dirname(os.path.abspath(__file__)),"chromedriver.exe")
    driver = webdriver.Chrome(executable_path=driverpath)

scenario 2

You can add the chromedriver path to environment "path" variable and use below example.

    driver = webdriver.Chrome()

This will find the chromedriver from system path variables.

You can add the chromedriver path to environment variables of based on operating system, below is the link for how to add path to windows 10 environment variables.

https://helpdeskgeek.com/windows-10/add-windows-path-environment-variable/

Upvotes: 0

user9261795
user9261795

Reputation: 363

You need to set the keep the the executables like chrome driver in locations present in the path variable.

Upvotes: 0

Kiran Sk
Kiran Sk

Reputation: 933

  1. Install pip in your machine - easy_install pip
  2. Then install chromedriver by simply typing : pip install chromedriver in terminal
  3. Then navigate to automation folder, type : python nameOfTheAutomation.py This will execute your automation code.

Upvotes: 1

Related Questions