To set up Selenium, you’ll first need to have Python installed. Check out my other posts if you need help with that.
Next, you need to install Selenium. To do this, simply open up your Windows command prompt or Mac/Linux terminal and enter the command:
1 |
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:
https://github.com/mozilla/geckodriver/releases
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:
1 2 3 4 5 6 7 8 |
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" browser.get(url) |
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.
Amar says
While trying to use all the latest versions of gecko, Firefox and Selenium, I am still getting an error saying that “Unable to find a matching set of capabilities”! I do not understand why. It would be great if any one could help me out here.
Grayson Stanton says
Hmm, that’s odd. You may want to verify that if you’re using the 32-bit version of firefox, you’re using the 32-bit geckodriver as well, or similarly for 64-bit versions.
There’s a long discussion here you might also want to read and see if anyone’s problems align with yours: https://github.com/SeleniumHQ/selenium/issues/3884
Otherwise, all I can think to try is to reinstall everything and hope for the best. I’ve never encountered this issue myself.