+91 88606 33966            edu_sales@siriam.in                   Job Opening : On-site Functional Trainer/Instructor | Supply Chain Management (SCM)
How to Locate Elements using XPath in Selenium

In this article, you’ll learn how to interact with form elements on a web page using XPath locators in Selenium WebDriver. By locating elements like input fields and buttons with XPath, you’ll automate actions such as typing text and clicking buttons. This is a fundamental skill in web automation and testing.

Below you can find the snippet of the HTML code used.




    
    Sample Form


    

Step 1: Setup and Open the Web Page

Start by importing necessary modules and initializing the WebDriver. Open the target HTML form using its URL.

Step 2: Locate and Interact with the Username Input Field

This XPath //input[@id='username'] targets an element with the specific attribute id="username" and used the send_keys() method to enter text into the input field.

Step 3: Locate and Interact with the Password Input Field

This XPath //input[@id=’password’] selects the element with the id="password" and used the send_keys() method to type in the password.

Step 4: Locate and Click the Login Button

This XPath //button[text()='Login'] targets a

Leave a Reply

Your email address will not be published. Required fields are marked *


Scroll to top