Menu
Python bindings for the Selenium WebDriver for automating web browser interaction. ## Installing the Selenium Python driver I installed Selenium using `pip` for Python 3: pip install selenium Since I was planning to use it from a Jupyter Notebook I actually installed it by running the following in a cell in a notebook:%pip install selenium The benefit of running this in the notebook is that you don't need to know the exact. Selenium is a web automation framework that can be used to automate website testing. Because Selenium starts a webbrowser, it can do any task you would normally do on the web. If you are new to selenium and browser automation, I recommend the course below. Related course Browser Automation with Python Selenium. If you already use Selenium 3, you may have existing browser tests and want to add coverage for Microsoft Edge (Chromium) without changing your version of Selenium.To use Selenium 3 to write automated tests for both Microsoft Edge (EdgeHTML) and Microsoft Edge (Chromium), install the Selenium Tools for Microsoft Edge package to use the updated driver.
In this tutorial, we will learn how to run a Selenium test script using Python Programming language.
Before going further in this tutorial, first, we will understand some essential points which will help us to implement test scripts in Python.
What is Selenium?
Kerio vpn free download for mac. Selenium is an open-source testing tool, which means it can be downloaded from the internet without spending anything. Selenium is a functional testing tool and also compatible with non-functional testing tools as well.
For further information about Selenium, refer the below link: https://www.javatpoint.com/selenium-tutorial
Why we use Selenium for automation testing?
Selenium is one of the most popular automation testing tools. Here automation testing is a process of converting any manual test case into the test scripts using automation tools such as Selenium.
Following are some aspects that, why we prefer Selenium for automation testing:
What is Python?
For further details about Python language, refer the below link: https://www.javatpoint.com/Python-tutorial
Why is Python useful for automation testing?
Selenium with Python
There are two ways to run a Selenium test scripts with the help of Python:
Let us see how we configure Selenium with the help of Python programing language:
Configure Selenium using Python
There are following steps to configure Selenium using Python:
Download and install Python for Windows
In this section, we will see how we download and install the Python for Windows platform.
Download the Python
To download the latest version of Python for Windows Platforms, refer the below link: https://www.Python.org/downloads/
Install the Python
![]()
After downloading the Python for Windows-64 bit, we will be ready to install the Python.
To install the Python, follow the below process:
Macos client for postgresql. After that, we will check whether Python is installed successfully and working fine or not.
So for this, we will open our command prompt, and type the command as Python and press the Enter key, and it will open the Python interpreter shell where we can implement the Python program as we can see in the below image:
Installing the Selenium libraries in Python
Once we successfully install the Python in our operation system, we will install the Selenium libraries.
For this, we will execute the following command in our command prompt:
And, this command will successfully install the latest Selenium package i.e., Selenium -3.141.0 added to the libraries as we can see in the below image:
After that executing the above command, it will create the Selenium folder automatically having all the Selenium libraries as we can see in the below screenshot:
Download and install PyCharm
Once we successfully install the Selenium libraries into Python, we are ready to download Python IDE that is PyCharm.
To download the PyCharm, follow the below process:
Create a new project and write the Selenium test script
Once we successfully install the PyCharm, we will open the PyCharm IDE for creating a new project.
Create a New Project in PyCharm
Follow the below process, to create a new project in PyCharm:
Adding Selenium Test Scripts
For adding the Selenium test scripts in the PyCharm, follow the below process:
Write the Selenium test script
For our testing purpose, we will first go to the Google Home page and search javatpoint from there.
We are creating our sample test script step by step to give you a complete understanding of how we write a Selenium test script in Python programming language.
For this, follow the below steps:
Step1
In the first step, we will type the following statement to import the web driver:
Step2
After that, we will open the Google Chrome browser.
As we can see in the below screenshot, we have multiple types of browsers options available, and we can select any browser from the list like Chrome, Edge, firefox, Internet Explorer, opera, safari, etc.
Following are the sample code for opening the Google Chrome browser:
Step3
![]()
In the next step, we will be maximizing our browser window size, and the sample code is as below:
Step4
Then, we will navigate to the given URL.
The sample code is as below:
Note: As we know that Python is a very easy language to write code because we don't have to write multiple statements like as we did it java. Or if we want to comment out something, we just simply put a hash[#] in our statements, or we can directly press Ctrl+ Forward slash [/] from our keyboard.
Step5
In this step, we are trying to locate the Google search text box with the help of its Name attribute value.
Here the sample code:
Step6
Once we identify the Google search text box, and we will identify the Google Search button.
So for this, follow the below process:
And, the sample code is as following:
Step7
In the last step, we are closing the browser.
And, the sample code for closing the browser is as follows:
Our final test script will look like this, after completing all the above steps:
Note:
|
Steps | Actions | Input | Expected Result |
---|---|---|---|
1. | Import web driver from Selenium. | Web driver should be imported. | |
2. | Open the Google Chrome browser. | The Google Chrome browser should be opened. | |
3. | Maximize the browser and delete all the cookies | The browser should be maximized, and cookies should be deleted. | |
4. | Navigate to the home page Gmail application. | https://www.gmail.com | The Gmail home page must be displayed. |
5. | Identify the username text box and pass the value. | [email protected] | The username text box should be identified and value should be entered in the username text box. |
6. | Click on the Next button. | The next button should be clicked. | |
7. | Identify the password text box and pass the value. | ####### | The password text box should be identified and value should be entered in the Password text box. |
8. | Click on the Next button. | The next button should be clicked. | |
9. | Close the Browser. | The Browser should be closed. |
Follow the below steps:
Download game dragon ball z ultimate battle 22. Step1
In the first step, we will import the web driver with the help of the following statement:
Step2
After that, we will open the Google Chrome browser.
- To launch the Google Chrome or any other browser (Firefox, ie, etc.), we need to download the executable files of the Chrome driver from the given link: https://sites.google.com/a/chromium.org/chromedriver/downloads
- Then, paste the downloading exe file in the Python package (demo) to overcome the exceptions as we can see in the below screenshot:
The sample code is as below:
Step3
In the next step, we maximize and delete all the cookies of the browser window.
Here the sample code:
Step4
In this step, we will navigate to the Gmail application URL.
The sample code is as below:
Step5
Once we navigate to the URL of the Gmail application, we will identify the username text box and passing the value of it.
To identify the username text box, follow the below process:
- Right-click on the username text box.
- And select the Inspect option in the given pop-up menu as we can see in the below screenshot:
- The developer tool window will open with all the specific codes used in the development of the usernametext box.
- Then, copy the value of its id attribute that is: identifierId as we can see in the below image:
- And, here the sample code:
Step6
In this step, we will identify the Next button and click on it.
To identify the Next button, follow the below process:
- Right-click on the next button, and click on the Inspect option in the given pop-up menu as we can see in the below image:
- The developer tool window will open with all the specific codes used in the development of the Next
- And, copy the value of its absolute XPath that is: //span[@class='RveJvd snByac'] from the chropath section as we can see in the below image:
- Here the sample code:
Step7
In this step, we will identify the password text box and pass the value of it.
To identify the password textbox, follow the below process:
- Right-click on the password text box, and click on the Inspect Option from the given pop-up menu as we can see in the below screenshot:
- The developer tool window will open with all the specific codes used in the development of the password text box.
- And, copy the value of name attribute, i.e., password as we can see in the below image:
Here the sample code:
Step8
In this step, we will identify the Next button and click on it.
To identify the Next button, follow the below process:
- Right-click on the next button, and click on the Inspect option in the given pop-up menu as we can see in the below image:
- The developer tool window will open with all the specific codes used in the development of the Next
- Copy the value of its absolute XPath that is: //span[contains(text(),'Next')] from the chropath section as we can see in the below image:
Here the sample code:
Step9
In the last step of the test script, we will close the browser.
Here the sample code:
And, our final test script will look like this after writing all the above steps successfully.
Selenium Python Mac
Note: In the above code, use your Gmail id at place: [email protected] and password: #########
Run the test script
To run the above test script, we will right-click on the code and then select Run As → Python Run as we see in the below screenshot:
The above test script will launch the Google Chrome browser and automate all the test scenarios.
And, as we can see in the below screenshot that our code is running successfully as we get the print message (output) on the console screen.
Selenium For Python 3
ChromeDriver
|
Comments are closed.
Author
Write something about yourself. No need to be fancy, just an overview.
Archives
December 2020
November 2020
October 2020