How to getText from the input field of an angularjs Applic | Selenium Forum
M
Posted on 25/07/2016
I have my DOM as below,

<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">

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

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.

Expected Text:

9161
Wesley
Choate

M
Replied on 26/07/2016

use this.
[code:zucmul9i]
for(int i=0;i<values.size();i++)
{
String theTextIWant = values.get(i).getText();
System.out.println(theTextIWant);

}[/code:zucmul9i]


M
Replied on 26/07/2016

I used getText() as well, But its retrieving blank value because there no text present between the tags but the text is visible in the UI.


M
Replied on 26/07/2016

send a screen shot.