Setting Up Webdrivers
This page explains how to set up the drivers required for Selenium Webdriver usage. This tutorial currently only covers Windows 10 and Python, but may be expanded in the future. To follow this tutorial make sure to
install Python if you haven't already.
Download a Driver
In order to use Selenium Webdriver, you need to download a driver for the browser you intend to test. You use
ChromeDriver for Chrome,
GeckoDriver for Firefox, and
IEDriver for Internet Explorer. Using Edge requires a bit more explaining - I will cover that later. Save the driver to a location of your choice, bearing in mind that the chosen folder will be where the driver lives from now on. I recommend storing all your web drivers in the same location, as it means you won't need to repeat this process again for subsequent drivers. Keep this location on hand - the file path is needed for the next step.
Set up the PATH
Once you have the driver downloaded, you will need to set up the environment variable to enable it. Press the Windows key to open the Start menu.
Without clicking any of the options, start typing - this will bring up the search menu. Type "environment", then select
Edit the system environment variables.
In the following menu, select
Environment Variables. Select the variable named
Path and click
Edit.
At this point, open the folder with the driver inside it if it isn't already open. Click on the address bar and copy the contents.
Back in the
Edit environment variable window, select
New, and paste the copied folder path into the text field, then select
OK on all the windows that have been opened up to this point.
Install Selenium
Open the Start menu again. This time, type "command" and select
Command Console.
Copy the following code, then right-click in the Command Console to paste it and hit Enter. (Because I already have it installed, it skips the installation.)
pip install -U selenium
Using Edge
Using Edge requires a bit more setup. The method to enable Edge usage depends on the version. For versions prior to 18, download
Microsoft Edge Legacy from the list on the
right. This acts the same as the other drivers.
However, versions 18 and later require the Command Prompt. Open the Start menu again. Type "command" again, and this time, right-click
Command Prompt and select
Run as administrator.
Copy the following code and paste it into the Command Prompt by right-clicking.
DISM.exe /Online /Add-Capability /CapabilityName:Microsoft.WebDriver~~~~0.0.1.0
Import and Use Selenium
At the top of the .py file, enter the following line of code.
from selenium import webdriver
When you go to actually open the browser, use one of the following code lines, depending on the desired browser.
browser = webdriver.Firefox() #Firefox
browser = webdriver.Chrome() #Chrome
browser = webdriver.Ie() #Internet Explorer
browser = webdriver.Edge() #Edge
--
LiamBarrett - 24 Jun 2020