Javascript 如何从angularjs应用程序的输入字段获取text()
我的DOM如下所示Javascript 如何从angularjs应用程序的输入字段获取text(),javascript,jquery,angularjs,selenium-webdriver,Javascript,Jquery,Angularjs,Selenium Webdriver,我的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
<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">
下面是执行上述代码时得到的输出
controller.model.value
controller.model.value
controller.model.value
从输出中,我可以说它只获取属性“ng model”中的值,而不是UI
中可见的实际文本。请告知如何获取在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);
}
预期文本:
9161
卫斯理
乔特
当您使用
ng model
作为属性时,只需在运行时从控制器获取模型值,并将该值设置为输入
。因此,您得到的是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);
}
List values=driver.findElements(By.xpath(//input[@ng model='controller.model.value']);
for(WebElement el:值)
{
字符串theTextIWant=el.getAttribute(“值”);
System.out.println(文本);
}
希望它能帮助……:)太好了:)这有帮助:)非常感谢:)为此感到高兴:)