Question

I'm stuck with one basic issue in Selenium WebDriver: How to test a capacity of the text field in the form? I have used .sendKeys(String) and then I tried to get the text back with .getText(), but it doesn't work. It retrieves an empty String. How to test the size of text field then? How to compare my input and actual data? This is my code:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.*;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
import org.testng.Assert;
public class main {
public static void main(String [] args){
WebDriver driver= new FirefoxDriver();
driver.navigate().to("http://energy-telecom.org/ServiceReview/quote.php");
String valid="0123456789";
WebElement element=driver.findElement(By.name("firstName"));
element.sendKeys(valid);
System.out.println("input: "+element.getText());
//Assert.assertEquals(element.getText(), valid, "Valid_TEXT");
}

} My output:

input:  

I know that I can use .getAttributes, but I'm curious can I retrieve this value. Obviously, the last line is commented because it gives an exception. Thank you. PS: Don't submit anything in this form pls :D

Was it helpful?

Solution

For input, the text is the value, so you may try

System.out.println("input: "+ element.getAttribute("value"));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top