Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何从angularjs应用程序的输入字段获取text()_Javascript_Jquery_Angularjs_Selenium Webdriver - Fatal编程技术网

Javascript 如何从angularjs应用程序的输入字段获取text()

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

我的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">
下面是执行上述代码时得到的输出

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(文本);
}
希望它能帮助……:)

太好了:)这有帮助:)非常感谢:)为此感到高兴:)