Overview
Selenium is a tool that take control over the browsers and simulate web surfing activities. Therefore, it is able to replicate any action typically undertaken by a user, such as clicking, typing and retrieving data from web pages. I will show you how to setup and run Selenium using Python.
Setup
# Install the python package manager, pip. apt-get install python-pip # Install Python bindings for Selenium. pip install selenium # Download Webdriver for Chrome from # <https://sites.google.com/a/chromium.org/chromedriver/downloads>. unzip chromedriver_linux64.zip
Run Selenium
- Close all instances of your Chrome browser.
- Run
./chromedriver
on 1 terminal and then run the Python code below from another terminal.
#!/usr/bin/python3 # Description: The Python code below will search selenium in Google. from selenium import webdriver from selenium.webdriver.common.keys import Keys driver = webdriver.Chrome() driver.get("https://www.google.com") search_box = driver.find_element_by_name('q') # Find search input box. search_box.send_keys('selenium') # Type in selenium. search_box.send_keys(Keys.RETURN) # Press ENTER. # Close. #driver.close()
Here is a video showing the code above in action.