This is our first article with video training on Python Selenium, in this article we are going to talk about Introduction & Installation of Selenium. we are going to install web drivers of selenium for Google Chrome and Mozila Firefox.
What is Selenium ?
Selenium is a set of tools for browser automation, and it is mostly used for testing applications. but the usage of selenium is not limited to testing of applications, but it can also be used for screen scrapping and repetitive tasks automation in a browser. so selenium supports automation for different browsers like firefox, internet explorer, google chrome, safari and opera.
There are different tools of selenium that you can use
- Selenium IDE: This is a Firefox add-in used to record and play back the
Selenium scripts with Firefox. It provides a graphical user interface to
record user actions using Firefox. - Selenium Web Driver: This is programming interface, and it is used with programming languages like Java,Python,C#, Ruby, PHP and JavaScript. and the web drivers supports different browsers like, Google Chrom, Mozila Firefox, Internet Explorer, Opera and Safari.
- Selenium Stand Alone Server: This is also known as Selenium Grid and allows remote and distrbuted execution of Selenium scripts created with WebDriver.
What is Python Selenium ?
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.5 and above.
Installation
You can install python selenium via pip like this.
1 |
pip install selenium |
Drivers
Selenium requires a driver to interface with the chosen browser, and there are different driver for each browsers that you need to download, it is just an exe file, after downloading just copy and paste the driver where you have installed your python. these are the most popular drivers download link for different browsers.
First of all you need to import web driver from selenium
1 |
from selenium import webdriver |
these line of codes are for opening of the chosen browser, for example in here we have used Google Chrome and Mozila Firefox.
1 2 |
driver = webdriver.Chrome() #driver = webdriver.Firefox() |
In here you can open a specific website
1 2 |
driver.get('https://www.codeloop.org') #driver.get('https://www.google.com') |
These are some web properties for the driver, like printing the title of the web page, current url and page source.
1 2 3 |
#print(driver.title) print(driver.current_url) print(driver.page_source) |
And these are some web browser commands, for example you can set the screen of the browser and also x and y position of the browser.
1 2 3 4 |
driver.fullscreen_window() #driver.maximize_window() #driver.set_window_size(300,300) #driver.set_window_rect(x=200, y = 200, width=200, height=200) |
This is used for closing of the browser, after the loading is completed.
1 |
driver.close() |
Also you can watch the complete video for Python Selenium Introduction & Installation
Subscribe and Get Free Video Courses & Articles in your Email