For testing, it becomes important to understand how to interact with the browser and locate the html elements. It is very easy to work with input fields with robot framework. In this chapter, we will learn how to work with textbox using Selenium Library. To work with input field – textbox, we need the locator, which is the main unique identifier for that textbox and it can be id, name, class, etc.
In this chapter, we will discuss the following areas −
We will first create a project in Ride to work with browsers. Open ride using ride.py from the command line.
Click New Project and enter Name of your project as shown below.
The name given for the project is Textbox. Click OK to save the project. Right-click on the name of the project created and click on New Test Case −
Name your test case and click OK to save it. We are now done with the project setup. Further, we will write test cases for the textbox. Since we need Selenium library, we need to import the same in our project.
Click on your project on the left side and use Library from Add Import.
Upon clicking Library, a screen will appear where you need to enter the library name −
Click OK and the library will get displayed in the settings.
The name given has to match with the name of the folder installed in site-packages.
In case the names do not match, the library name will show in red as in the following screenshot −
We are now going to write test cases. The test case details will be as follows −
Open browser − URL − https://www.tutorialspoint.com/ in Chrome
Enter data in the search textbox in https://www.tutorialspoint.com/
To work with textbox, we need a locator. A locator is the identifier for the textbox like id, name, class, etc. For example, if you are using the −
name attribute of the textbox, it has to be name − Nameofthetextbox or name=Nameofthetextbox
id of the textbox, it will be id:idoftextbox or id=idoftextbox
class of the textbox, it will be class − classfortextbox or class=classfortextbox
Now, we will add the details of the test case for textbox in ride. Here are the keywords entered for textbox test case −
Open Browser − The keyword opens the browser for the given URL and the browser specified.
Input Text − This keyword works on the input type and will look for the locator name:search on the site https://www.tutorialspoint.com/ and angularjs is the value we want to type in the textbox.
Click button is used to click on the button with location class:gsc-search-button-v2.
We will now execute the same −
Upon clicking the Search icon, a screen will appear as shown in the following screenshot −
Let us now see the reports and the log details −
We have seen how to interact with the textbox using selenium library in robot framework.Using the keywords available with robot framework and the library imported we can locate the textbox and enter data and test the same.