Waruna Gunaratne Waruna Gunaratne - 1 year ago 123
Javascript Question

When I use to selenium java test script retrieve data from angular model but run time I get : no such element: Unable to locate element: errors

I get the following error when I use to selenium Java test script to retrieve data from angular model no such element: Unable to locate element: errors

<div class="col-md-11 textfielddiv">
<textarea id="textboxc7f95f05-5de7-497f-b91f-20df0fc69120" class="form-control textfield ng-pristine ng-untouched ng-valid ng-empty" ng-model="chatPane.textmessage" ng-keypress="isType(chatPane.VisitorId)" ng-enter="sendChat(chatPane.VisitorId)" placeholder="Type your message here" cols="50" rows="3" aria-invalid="false"/>

To retrieve data, I use below code:

Login1 = driver.findElement(By.cssSelector("input[ng-model='chatPane.VisitorId']"));
System.out.println("chatPane.textmessage+ "+Login1.getAttribute("value"));

Run time error

org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"input[ng-model='chatPane.VisitorId']"}
(Session info: chrome=51.0.2704.103)

Answer Source

I don't see input tag there. Try this:

 Login1 = driver.findElement(By.cssSelector("textarea[ng-model='chatPane.textmessage']"));
 // I don't see value attribute either.
 System.out.println( chatPane.textmessage +Login1.getAttribute("value"));

you can get inner HTML text with Login1.getAttribute("innerHTML"); However, I do not see any text here.

Since you want to get VisitorID get Attribute "ng-enter".

Login1 = driver.findElement(By.cssSelector("textarea[ng-model='chatPane.textmessage']"));
String visitorId=Login1.getAttribute("ng-enter");

I hope it gives the text if it doesn't return text. Then try this.

String visitorId=((JavascriptExecuter)driver.executeScript(chatPane.VisitorId);

I hope it works. Let me know in comment.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download