如何从angularjs应用程序的输入字段中获取文本() [英] How to getText() from the input field of an angularjs Application

查看:87
本文介绍了如何从angularjs应用程序的输入字段中获取文本()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的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 中对用户可见。

I want to getText() from the above input tag. I tried below methods, but since this is a JSapplication I am unable to getText. Though the text is not visible in the DOM but it is visible for the user in the 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);

    }

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

Below is the output I get when the above code is executed.


controller.model.value

controller.model.value

controller.model.value

controller.model.value

controller.model.value

controller.model.value

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

From the output I can say that it just gets the value present inside the attribute "ng-model" but not the actual text that is visible in the UI. Please advice how can I get the text that is visible in the UI.

预期文本:


9161

9161

Wesley

选择


推荐答案

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

As you are using ng-model as an attribute, It's just use to getting the model value from the controller at runtime and set to this value to the input. So in this reason you are getting the ng-model property instead of real value.

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

Actually input element contains their value in value attribute, So you should try as below :-

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);
}

希望它有帮助...:)

Hope it helps...:)

这篇关于如何从angularjs应用程序的输入字段中获取文本()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆