selenium

Selenium WebDriver get text from input field


I'm writing a test to assert the default text value within an <input> tag. However, it's not playing ball:

Assert.assertThat(webDriver.findElement(By.id("inputTag")).getText(), Matchers.is("2"));

Solution

  • This is the input element - you need to get the value attribute:

    webDriver.findElement(By.id("inputTag")).getAttribute("value")