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

2

There are 2 best solutions below

0
On BEST ANSWER

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

If you are working with angular, I would suggest you to use Protractor

To submit text in input:

using Protractor;

var ngDriver = new NgWebDriver(driver);
//Go to your url
ngDriver.WaitForAngular();

string s = "Test";
IWebElement query = ngDriver.FindElement(By.Id("input_30"));
query.SendKeys(s);

to get text from input:

var x = ngDriver.FindElement(By.Id("put the id here")).Text;