Installing Selenium and fixing issues related to Chromedriver in linux

Selenium Python bindings provides a simple API to write functional/acceptance tests using Selenium WebDriver. Through Selenium Python API you can access all functionalities of Selenium WebDriver in an intuitive way.

Selenium Python bindings provide a convenient API to access Selenium WebDrivers like Firefox, Ie, Chrome, Remote etc. The current supported Python versions are 2.7, 3.2, 3.3 and 3.4.

Downloading Python bindings for Selenium

You can download Python bindings for Selenium from the PyPI page of selenium package. However, a better approach would be to use pip to install selenium or other python packages.

STEP 1 : Open your console and type :

 sudo apt-get install python-pip 

STEP 2 : Type the following command to install selenium binding for linux.

 sudo pip install selenium 

STEP 3 : Type or paste the following code in your favorite text editor.

from selenium import webdriver

driver = webdriver.Chrome() # you can use Firefox or PhantomJS
driver.get("http://www.python.org")

STEP 4 : Open terminal and type

 cd you/path/to/code/filename.py

and hit Enter.

STEP 5 : If the chrome or chromium browser open after hitting enter. You can continue learning selenium. But if you see the following result :

driver = webdriver.Chrome()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 61, in __init__
self.service.start()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/service.py", line 73, in start
os.path.basename(self.path), docs_msg)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chrome

. Then follow the next step.

STEP 6 : Goto ChromeDriver Storage and download the file -> save it -> extract the file on Desktop.

STEP 7 : Open Terminal ( CTRL + ALT + T ) and type

 cd desktop 

STEP 8 : Before moving the file to make it available, change the properties of the file, and for that, follow the steps given below. Screenshot from 2015-10-18 23:49:45 Now, type

 sudo mv chromedriver /usr/bin 

STEP 9 : Now, for sake of convenience make it executable using the following command, first type :

 sudo cd /usr/bin 

then

 chmod +x webdriver 

STEP 10 : Run the above python code, again. Or use another code to test it, which is :

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()

Boom 😀 It runs without giving any error 🙂

Advertisements

One thought on “Installing Selenium and fixing issues related to Chromedriver in linux

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s