Next, you need to install Selenium. To do this, simply open up your Windows command prompt or Mac/Linux terminal and enter the command:
pip install selenium
Now that Selenium is installed, you need to pick a web browser for Selenium to use. Firefox and Chrome are both just as easy to use with Selenium, but here we’ll look at using Firefox. Assuming you have the Firefox browser installed on your machine, go to the following webpage:
Click to download the appropriate “gecko driver” zip file for your machine. Unzip the driver and move it to whatever place in your file system you prefer. Just keep in mind you will need to reference the gecko driver’s location when you use Selenium.
Finally, to make sure everything is working as it should, run this code:
from selenium import webdriver
# your executable path is wherever you saved the gecko webdriver
geckodriver = "C:\\Users\\gstanton\\Downloads\\geckodriver.exe"
browser = webdriver.Firefox(executable_path=geckodriver)
url = "https://www.duckduckgo.com"
If a Firefox browser pops up and takes you to DuckDuckGo’s home page, you’re all set!
If something’s not working, make sure Selenium, Firefox, and gecko driver are all up-to-date and try again. If all else fails, leave a comment and we’ll figure it out.