Reputation: 137
I have executed e2e test for following code using angular
it('should successfully login and create a session using valid credentials', function() {
browser.get('http://www.angularjs.org');
browser.driver.manage().deleteAllCookies();
var username = element(by.model('username'));
var password = element(by.model('password'));
username.sendKeys('admin');
password.sendKeys('password');
});
but i got error like this
NoSuchElementError: No element found using locator: by.model("username")
how to solve this issue.
Upvotes: 2
Views: 5617
Reputation: 2197
You should build your Protractor test not based on assumptions, but with the assistance of tools such as element explorer and elementor.
Then, you can claim, that there is a problem.
Without those tools, writing Protractor test becomes very slow process.
Link to elementor repo: https://github.com/andresdominguez/elementor
Upvotes: 3
Reputation: 6962
Are you sure that your element exists in DOM. If yes, then you should wait for angular to settle down and then try to check for the elements. If the element is still loading then protractor will throw an error. Include ignoreSynchronization
to make sure protractor waits for angular to settle. You can provide explicit wait time for element to be visible or wait until it loads -
it('should successfully login and create a session using valid credentials', function() {
browser.driver.manage().deleteAllCookies();
browser.ignoreSynchronization = false;
browser.get('http://www.angularjs.org');
var username = element(by.model('username'));
var password = element(by.model('password'));
browser.sleep(2000);
browser.wait(protractor.ExpectedConditions.visibilityOf(username), 20000);
username.sendKeys('admin');
password.sendKeys('password');
});
Hope this helps.
Upvotes: 2