Selenium

Setup selenium webdriver in python

Selenium WebDriver is one of the most popular tools for Web UI Automation. And no better than Python can complement it to automate a broad range of web applications.

Selenium is an open source, and its library is available in different programming languages to perform the Web UI Automation testing, and Python is one of them.

Selenium WebDriver Client Library for Python enables us to utilize all the features available with Selenium WebDriver and interact with Selenium Standalone Server to perform Automated testing (both remote and distributed testing) of browser-based applications.

Installing Python

On Linux Distributions, MAC OS X, and Unix machines; Python is by default installed.

However, on Windows machines, it needs to be installed separately. Python installers for different Operating Systems are available here:

After you run the Python installer, it also installs the <pip> tool which is Python’s package manager. It facilitates the installation of advanced packages like the Selenium Webdriver.

Set/Add the environment variable for python : System Properties->Advanced->Environment Variables

Go to CMD and type python if it successfully installed you will get below:

Installing Selenium Webdriver Python Package

Use the <pip> tool to install the Selenium Webdriver package.

If you want to upgrade the currently installed Selenium Webdriver package then, just add the -U flag to the previous <pip> command. Since we already have the latest version of the Selenium Webdriver library, the upgrade command will return the status as up-to-date.

C:\python\python35>pip install -U selenium
Requirement already up-to-date: selenium in c:\python\python35\lib\site-packages
←[33mYou are using pip version 7.1.2, however, version 8.1.0 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

This approach is the safest of all the methods available for installing Selenium with Python. The above commands will set up the Selenium WebDriver library on the system that contains all modules and classes required to create automated test scripts using Python.

Prerequisites

Download and install  PyCharm IDE for python.

Setup project in PyCharm:

1. Launch PyCharm and Click “+Create New Project“.

2.Provide a project name and click on Create button

3. Go to File->Settings

4. Go to Project:qautomation -> project Interpreter -> Click + to add selenium package.

5.Search Selenium and Click on Install Package .

6. After successful install of package you will see a message and selenium package . Click OK.

Launching Different Browsers

1.Create a python file by right clicking the project and go to New->Python File

2.Enter the name of file and click OK button

3.Chrome Browser : Download chrome driver and use below code to launch the chrome browser:

from selenium import webdriver

driver = webdriver.Chrome(executable_path='C:/Users/mnazim/PycharmProjects/NazimDev/chromedriver.exe')
driver.implicitly_wait(30)
driver.maximize_window()
driver.get("http://www.google.com")

4. FireFox Browser : Download FireFox driver and use below code to launch the FireFox browser:

from selenium import webdriver

driver = webdriver.Firefox(executable_path='C:/Users/mnazim/PycharmProjects/NazimDev/geckodriver.exe')
driver.implicitly_wait(30)
driver.maximize_window()
driver.get("http://www.google.com")

5. IE Browser : Download IE driver and use below code to launch the IE browser:

from selenium import webdriver

driver = webdriver.Ie("C:\\Users\\mnazim\\PycharmProjects\\NazimDev\\IEDriverServer.exe")
driver.implicitly_wait(30)
driver.maximize_window()
driver.get("http://www.google.com")

References:

https://pythonspot.com/selenium/

https://www.seleniumhq.org/docs/03_webdriver.jsp#selenium-webdriver-s-drivers

Categories: Selenium

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s