java.lang.AssertionError: found value shows as null

java.lang.AssertionError: found value shows as null

我想检查文本字段值是否与我在代码中提到的预期值相同

这是文本字段,我需要它的值

输入类型="text"值="sadas"class="mdl-textfield__input"id="last_name"名称="last_name"占位符="Enter last name"

错误我得到了什么,

TestNG报错信息如下, java.lang.AssertionError:预期 [6234] 但发现 [] 也没有为控制台打印任何内容

我试过 "Assert.assertTrue(lastName.equals("lastName : 6234"));"太

@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("x@gmail.com");
    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();
    }

我该如何解决这个问题?为什么当期望值与找到的值相同时我会收到此错误?(手动检查系统时)

尝试在获取姓氏字段的值之前添加等待。您在获取姓氏值之前单击 link,页面可能未完全加载。

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");