Selenium WebDriver从输入字段获取文本

Mat*_*hew 6 selenium

我正在编写一个测试来断言<input>标签中的默认文本值.但是,它不是在打球:

Assert.assertThat(webDriver.findElement(By.id("inputTag")).getText(), Matchers.is("2"));
Run Code Online (Sandbox Code Playgroud)

ale*_*cxe 15

这是input元素 - 您需要获取value属性:

webDriver.findElement(By.id("inputTag")).getAttribute("value")
Run Code Online (Sandbox Code Playgroud)

  • 在python(3)中,它称为`get_attribute`。 (3认同)
  • 当用户进行更改时,“值”属性似乎并不总是更新。由于“getText()”不起作用,在这种情况下您会建议什么? (2认同)