如何从angularjs应用程序的输入字段中获取文本()

我有我的DOM如下,

 

我想从上面的输入标记getText() 。 我尝试了下面的方法,但由于这是一个JSapplication我无法getText 。 尽管文本在DOM不可见,但在UI对用户可见。

 List values = driver.findElements(By.xpath("//input[@ng-model='controller.model.value']")); for(int i=0;i<values.size();i++) { String theTextIWant = values.get(0).getAttribute("ng-model"); System.out.println(theTextIWant); } 

下面是我执行上述代码时得到的输出。

controller.model.value

controller.model.value

controller.model.value

从输出中我可以说它只是获取属性“ng-model”中存在的值,而不是UI可见的实际文本。 请告知如何获取UI可见的文本。

预期文本:

9161

韦斯利

乔特

当您使用ng-model作为属性时,它仅用于在运行时从控制器获取模型值,并将此值设置为input 。 因此,您正在获取ng-model属性而不是实际值。

实际上input元素在value属性中包含它们的值,所以你应该尝试如下: –

 List values = driver.findElements(By.xpath("//input[@ng-model='controller.model.value']")); for(WebElement el : values) { String theTextIWant = el.getAttribute("value"); System.out.println(theTextIWant); } 

希望能帮助到你…:)