我的 DOM 如下所示,
<input class="k-textbox ng-pristine ng-untouched ng-valid ng-valid-required" type="text" placeholder="" ng-blur="controller.isDirty=true" ng-change="controller.isDirty=true" ng-model="controller.model.value" ng-required="controller.model.required" ng-disabled="controller.model.readOnly" ng-focus="controller.showFieldHistory(controller)" disabled="disabled">
我想从上面的输入标签中获取getText()
。我尝试了以下方法,但由于这是一个 JSapplication
,所以我无法 getText
。虽然文本在 DOM
中不可见,但在 UI
中对用户可见。
List<WebElement> 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
Wesley
Choate
最佳答案
当您使用 ng-model
作为属性时,它仅用于在运行时从 Controller 获取模型值并将此值设置为 input
。因此,出于这个原因,您将获得 ng-model
属性而不是实际值。
实际上 input
元素在 value
属性中包含它们的值,所以你应该尝试如下:-
List<WebElement> values = driver.findElements(By.xpath("//input[@ng-model='controller.model.value']"));
for(WebElement el : values)
{
String theTextIWant = el.getAttribute("value");
System.out.println(theTextIWant);
}
希望对您有所帮助...:)
关于javascript - 如何从 angularjs 应用程序的输入字段中获取 getText(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38564317/