Search code examples
selenium-webdrivercucumber-java

How to get the text from textarea of Anjular an JS element, When i tried using getText() it is returning empty text and if i used ng-model


Html code of Element I want to get text:

<textarea ng-model="event.additionalInfo" maxlength="255" rows="1" md-no-autogrow="false" md-no-resize="false" data-ng-disabled="eventNotEditable" class="ng-valid md-input ng-valid-maxlength ng-dirty ng-valid-parse ng-touched ng-not-empty" id="input_30" aria-invalid="false" style=""></textarea>

How I'am trying:

WebElement element= driver.findElement(By.id("input_30"));
String s = RandomStringUtils.randomAlphanumeric(256);
element.sendKeys(s);
Thread.sleep(2000);
    System.out.println(element.getText());

If there is any best way please let me know, Thanks in advance for any help


Solution

  • Sorry for not being clear in my Question, This Post solved my Problem

    How to getText() from the input field of an angularjs Application

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