Waruna Gunaratne Waruna Gunaratne - 4 months ago 15
AngularJS Question

Using selenium java need to retrieve data from angularjs

I need to retrieve data from the DB using angularjs to selenium java.

Below steps I tried but I couldn't retrieve data.

Use Selenium code---

HTML page source

`<div class="col-sm-6">
<input id="LastName" class="form-control ng-pristine ng-untouched ng-empty ng-invalid ng-invalid-required" type="text" required="" ng-model="UserProfiles.LastName" name="LastName" placeholder="Please Enter Last Name"/>
</div>`


Selenium Java code

WebElement cityField = driver.findElement(By.cssSelector("input[ng-model='UserProfiles.FirstName']"));

cityField.clear();
cityField.sendKeys("Chicago");
System.out.println("Print- "+ cityField.getAttribute("input[ng-model='UserProfiles.FirstName"));

cityField = driver.findElement(By.cssSelector("input[ng-model='UserProfiles.LastName']"));
System.out.println("+++-- "+cityField.getText());`

Answer

Your code is attempting to get the text inside an "input" element, which will return nothing. Please try

cityField.getAttribute("value")
Comments