0
votes

I wanted check whether the text field value is same or not to the expected value which i mentioned on the code

@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();
Assert.assertEquals(driver.findElement(By.xpath("//input[@name='last_name']")).getText(),"sadas");    
driver.findElement(By.linkText("Log Out")).click();
}

This is the text field which i need to get the value

input type="text" value="sadas" class="mdl-textfield__input" id="last_name" name="last_name" placeholder="Enter last name"

The code mentioned below got the AssertionError, Assert.assertEquals(driver.findElement(By.xpath("//input[@name='last_name']")).getText(),"sadas");

I found the error as , java.lang.AssertionError: expected [sadas] but found []

How can i fix this? And why i'm getting this error when expected value same to the found?(when manually checking the system)

2

2 Answers

0
votes

Please add the html code which you are accessing using above script

0
votes

This code will help to locate the particular text, this one is Javascript.

String expectedMessage = "Please enter password.";
    String message = w.findElement(By.xpath("//*[@id=\"sign_in_div\"]/form/div/ul/li[2]/div")).getText();
    Assert.assertTrue("Please enter password.", message.contains(expectedMessage));