2016-07-25 36 views
2

的输入字段我有我的DOM如下,如何gettext的()从angularjs应用

<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中可见的文字。

预期的文本:

韦斯利

乔特

回答

1

当您使用ng-model为一个属性,它只是用来从控制器获取模型值在运行时并将此值设置为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); 
} 

希望它能帮助... :)

+0

优:)这有助于:)谢谢你多:)为此感到高兴:) –