≤90s: Install Selenium for Python on Ubuntu
March 26, 2020
Project: lte-90-sec
In this video, we learn how to set up Selenium in 90 seconds or less! Made using Ubuntu on Windows (WSL). You may need to start an Xming server if you use this method (I did).
Steps
1. Install packages.sudo apt update && sudo apt install python3 python3-pip firefox
geckodriver
.
2. Download geckodriver
wget https://github.com/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-linux64.tar.gz
geckodriver
.
3. Untar geckodriver
tar xvf geckodriver-v0.26.0-linux64.tar.gz
geckodriver
into system PATH
.
4. Copy geckodriver
PATH
Edit:
may be more appropriate than /usr/local/lib
because /usr/lib
is typically the place for user-installed software (whereas /usr/local/lib
is for the package manager). Use whichever you prefer, but if you decide to use /usr/lib
, make sure that it is in your /usr/local/lib
environment variable.$PATH
sudo cp geckodriver /usr/lib
selenium
Python package.
5. Install the selenium
pip3 install selenium
verify.py
and make sure Selenium is working.
6. Edit verify.py
vi verify.py
#!/usr/bin/env pythonfrom selenium import webdriverbrowser = webdriver.Firefox() browser.get('http://www.google.com/')
7. Run the test script.python verify.py
8. Try writing a unit test with Selenium.vi test_selenium.py
from selenium import webdriver
class TestGoogle(unittest.TestCase): def setUp(self): self.browser = webdriver.FireFox() def test_title(self): self.browser.get('http://www.google.com/') self.assertIn('Google', self.browser.title) def tearDown(self): self.browser.close()
if __name__ == '__main__': unittest.main()
9. Run your test.python test_selenium.py
Need Python? We have a tutorial for that, too! Install Python in 90 seconds or less on Windows or on Ubuntu.
Project: lte-90-sec