Scripting >> Selenium >> Python >> Getting started with Selenium on Python in Windows environment

 

INSTALL Selenium module for Python


## Assuming that you already have Python 3 installed

C:\windows\system32> pip install selenium

 

DOWNLOAD Webdrivers 


## Download the webdriver for the required browsers to automate

Browser Download URL webdriver .exe name
Chrome [OLD] https://sites.google.com/a/chromium.org/chromedriver/downloads

[NEW] https://sites.google.com/chromium.org/driver/
 
chromedriver.exe
Edge https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/  
Firefox https://github.com/mozilla/geckodriver/releases geckodriver.exe
Safari https://webkit.org/blog/6900/webdriver-support-in-safari-10/  


## Unzip these drivers and place the .exe file into a folder that is Windows PATH for all users

e.g. if C:\Python3 is already in PATH, copy the webdriver .exe into c:\python3

e.g. if not, put into a folder such as c:\webdriver and then open a command prompt as administrator and

C:\windows\system32> SETX /M PATH "%PATH%;C:\webdriver"

 

 

 TEST RUN


## create a test python script browser.py as follows and execute

c:\scripts\browse.py
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)


## It should launch Chrome browser and then load the URL and enter "pycon" into the search box and press Return


## to close the Chrome browser automatically add to the bottom of the script

driver.close()
 
 

 

DISCOVERING THE Selenium API


## launch Python intepreter and then


>>> import selenium
>>> help('selenium.webdriver.Firefox')

 

 

 

 

 

 

 

 

 

 

 

 REFERENCES

  1. https://www.selenium.dev/selenium/docs/api/py/api.html