By Arun Motoori
As we have already gone through the getAttribute(“value”) method in our previous post #37 Using getAttribute(“value”) method for retrieving text from the text fields , go through this post to rewind before going to the next steps.Test Description:Now lets use getAttribute(“value”) method to retrieve the Username text value entered into the Username text box field as explained in the below screenshot:
Lets Implement the Test on Eclipse IDE:Pre-requisites:1. Create a new Java Project say ‘WebDriver-Project59’ in Eclipse IDE2. Configure the Project to work with Selenium WebDriver3. Create a package say ‘package59’ under the newly created project.4. Create a Java Class file say ‘Class59’ under the newly created package as shown below:
Actual Steps:1. Write the following code into the newly created Java Class file as shown below and make sure that you resolve all the errors before going to next step:
2. Create a test method ‘typeRetrieveAndVerify()’ as shown below:
3. Use Selenium WebDriver command sendKeys( ) for entering the Username value say ‘User143’ into the ‘Username’ text box field as shown below:
4. Use Selenium WebDriver command getAttribute(“value”) method for retrieving the text value from the Username text box field and also use JUnit method assertEquals( ) to verify whether the text retrieved by the getAttribute(“value”) method is equal to the text entered by the sendKeys( ) command as shown below:
5. Save and Run the ‘Class59.java’ file by selecting the ‘JUnit Test’ option and ensure that our Automation Test has passed to confirm that the text retrieved from the Username text box field using getAttribute(“value”) method is equal to the text entered into the Username text box field using sendKeys( ) method as shown in the below video:Watch the below video:Click here to watch the video.Download this Project:
Click here to download this project and import into Eclipse IDE on your machine.Please comment below to feedback or ask questions.
Using getAttribute(“value”) method with Password field will be explained in the next post.