Automation Fever

How To Type Text in Textbox Using Selenium

So Far, we have learned how to use VBA Selenium to open websites. However, it is now time to execute some actions on a website. In forthcoming articles, we will discuss various actions that can be performed on a website. This article will focus on typing text into a textbox, while future articles will cover other actions.
You can see there are two textboxes when you open ‘acme-test/uipath.com’ in your browser; the first one is for entering the email address, and the second one is for entering the password. In this article, we’ll walk you through how to input data into these two input fields.

When we intend to input text into a textbox, it is necessary to locate it on the website. In Selenium, all visible components on the website are considered elements. Therefore text boxes for passwords and emails are also elements for us.
The method that we use to locate an element on a website is known as locators. There are various ways to find elements on a webpage. Below is a list of all available locators:

⦁ ID
⦁ Name
⦁ Class Name
⦁ Tag Name
⦁ Link Text
⦁ Partial Link Text
⦁ XPATH
⦁ CSS

For this tutorial, we will be using the ID locator. Other locators will be covered in future articles.

Now, place your mouse cursor over the email textbox and click on the right mouse button, then select “Inspect” option from the drop-down list, to open “Developers Tools”

You can find a highlighted input element under “Developer Tools”. In HTML, a tag is referred to as an element. As you can see, the input tag has a few attributes, like id, type, class, name, etc. These attributes can be used to locate the email textbox. To locate this element, let’s use the id locator.

To find the email input box, we need to use ChromeDriver.FindElementById(element id) function, and then text can be entered using the SendKeys function. As a result, the code to type in the email input field should look like this:
ChromeDriver.FindElementById(element id).SendKeys “Text to enter”

e.g.
driver.FindElementById(“email”).SendKeys “queries.automation@gmail.com”

Now we also need to find the locator for the password input box. So, we can enter the password in the password input box. Let’s keep our mouse cursor on the password input box and press right click and then choose Inspect from the dropdown

The highlighted element contains an id attribute as well, thus ID can be used to enter a password :
Driver.FindElementById(‘password’).SendKeys “automation.fever”

Hence, the code below can be used to enter data into both input boxes:

Private driver As Selenium.ChromeDriver

Sub EnterTextInTextbox()
Set driver = New Selenium.ChromeDriver

driver.Start
driver.Get “https://acme-test.uipath.com”

driver.FindElementById(“email”).SendKeys “queries.automation@gmail.com”
driver.FindElementById(“password”).SendKeys “automation.fever”
End Sub

Screenshot of VB Editor :

Output :

Scroll to Top