Verification of data after entering in a textbox. | Selenium Forum
M
Posted on 15/10/2015
Hi Ashish,

I have started working on the automation of the website on which I am working.
I am able to enter the data in the text fields by the use of sendKeys function but I wanted to verify one thing.

After entering the data, what is the best way to verify whether the text that I have entered in the text box is actually entered or not?

I am using the following to verify whether the data that I sent to the text box is actually entered successfully.

Example of a data entered in a text box:( verifying the information in the text box) In a textbox I am entering "Computer Equipment".

Code is as follows:
----------------------------
String actualText = driver.findElement(By.xpath("//tbody/tr[2]/td[2]/input")).getAttribute("value");
System.out.println(actualText);
String expectedText = "Computer equipment";
if (actualText.contains(expectedText))
System.out.println("verified the entered text");
else
System.out.println("not verified");

I am planning to use the getAttribute for this.

Could you please help me in this doubt? and Do we need to use this for the verification of every text box in which I am sending the data?

If you can provide any link for reference that would also be very helpful.

M
Replied on 16/10/2015

yeah it should work everywhere.

or try this


String actualText = driver.findElement(By.xpath("//tbody/tr[2]/td[2]/input")).[color=#FF0000:ztip90l1]getText;[/color:ztip90l1]
System.out.println(actualText);
String expectedText = "Computer equipment";
if (actualText.contains(expectedText))
System.out.println("verified the entered text");
else
System.out.println("not verified");