Is Selenium Web Driver (Firefox) able to read the initial values โ€‹โ€‹of AngularJS ng-model?

I have an input text box associated with a javascript object using an ng model. The javascript object provides the initial value for the field.

<input class="class1 class2" type="text" ng-model="scopeVar"></input> 

scopeVar is a text value.

When the page loads, Selenium (using the firefox driver) can find the input field, make sure it is visible, can enter text in the field, and then read the text back, but it cannot read the text that was originally in the field.

If I run $ ('. Class1.class2'). val () in the Firefox browser window, it returns the expected default value.

If I execute the ((JavascriptExecutor) driver) .executeScript ("$ ('. Class1.class2'). Val ()"), it returns null. If I run the driver .driver.findElement (By.cssSelector (". Class1.class2")). GetText () returns null.

So, it looks like Angular is populating the DOM correctly (as far as jQuery is concerned), but Selenium Web Driver cannot read it.

Note. I check that I have an element and that it is displayed before I try to read it.

Any help is appreciated.

+4
source share
1 answer

I do not know about your application, but this works against the ng model input field being displayed:

  WebDriver wd = new FirefoxDriver(); wd.get("http://jsfiddle.net/SAWsA/11/show/"); WebElement input = wd.findElement(By.tagName("input")); input.sendKeys("hello"); input = wd.findElement(By.tagName("input")); System.out.println("fieldValue=" + input.getAttribute("value")); wd.quit(); 

And there is also ngWebDriver for Java .

+5
source

Source: https://habr.com/ru/post/1488330/


All Articles