Reputation: 39
I wanted check whether the text field value is same or not to the expected value which i mentioned on the code
This is the text field which i needed the value
input type="text" value="sadas" class="mdl-textfield__input" id="last_name" name="last_name" placeholder="Enter last name"
Error what i got,
TestNG error message shows as follows, java.lang.AssertionError: expected [6234] but found [] and nothing printed for the console as well
I have tried with "Assert.assertTrue(lastName.equals("lastName : 6234"));" too
@Test
public void tc001() {
driver.get(baseUrl);
driver.findElement(By.xpath("//input[@name='email']")).click();
driver.findElement(By.xpath("//input[@name='email']")).clear(); driver.findElement(By.xpath("//input[@name='email']")).sendKeys("[email protected]");
driver.findElement(By.xpath("//input[@name='password']")).clear();driver.findElement(By.xpath("//input[@name='password']")).sendKeys("123456");
driver.findElement(By.xpath("(.//*[normalize-space(text()) and normalize-space(.)='Forgot Your Password?']) [1]/preceding::button[1]")).click();
driver.findElement(By.linkText("Nadee")).click();
driver.findElement(By.linkText("Profile")).click();
String lastName = driver.findElement(By.xpath("//input[@name='last_name']")).getText();
Assert.assertEquals(lastName ,"6234");
System.out.println(lastName);
driver.findElement(By.linkText("Log Out")).click();
}
How can i fix this? And why i'm getting this error when expected value same to the found?(when manually checking the system)
Upvotes: 0
Views: 2662
Reputation: 388
try to add wait before getting value of lastname field. You are clicking a link before getting last name value, there is a possibility that page was not fully loaded.
driver.findElement(By.linkText("Profile")).click();
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@name='last_name']")));
String lastName = driver.findElement(By.xpath("//input[@name='last_name']")).getAttribute("value");
system.out.println("Last Name value is: "+ lastName); // check the output on console too
Assert.assertEquals(lastName ,"6234");
Upvotes: 1