Python Selenium Basics

In this article we want to learn about Python Selenium Basics, so 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.



Python Selenium Basics

For working with the example of this tutorial you need some requirements, first you should have installed Python in your system, then we need to install Python Selenium and you can use pip for that like this, also you need to driver for specific browser.



Note: You can download the drivers from here.





To begin with Selenium, we first need to import the necessary modules and create an instance of a web driver. Below is an example of launching the Chrome browser:



After launching the browser, we can instruct Selenium to navigate to a specific URL. Let’s use the page as an example:



Selenium provides different methods to interact with web elements such as buttons, input fields and dropdowns. We can locate elements using different techniques, including XPath, CSS selectors and element IDs. This is an example of logging in by filling in the username and password fields:




Web pages may load at different speeds, and elements may appear dynamically. To ensure that our automation scripts work reliably, we can incorporate wait times to synchronize with the page loading process. This is an example of using an explicit wait to wait for an element to become clickable:




This is the complete code



Learn More on Python Selenium 

Leave a Comment