So, I am trying to test my login page using protractor e2e testing for my ionic app. This is my first time using protractor and I am having trouble understanding the error that I am getting.

Error:- Failed: no such element: Unable to locate element: {"method":"css selector","selector":"*[id="user1"]"}

I'm stuck, i just need guidance. It's my first time testing.


describe('Login tests', () => {


it('login page works', function() {
  // Checking the current url
  var currentUrl = browser.driver.getCurrentUrl();

it('should sign in', function() {

// Find page elements
 var userNameField = browser.driver.findElement('username'));

 var userPassField = browser.driver.findElement('password'));
//  var userLoginBtn  = browser.driver.findElement('loginbtn'));

// Fill input fields
userNameField.sendKeys('[email protected]');

// Ensure fields contain what we've entered
// expect(userNameField.getAttribute('value')).toEqual('[email protected]');
// expect(userPassField.getAttribute('value')).toEqual('123456');

// Click to sign in - waiting for Angular as it is manually bootstrapped.

return browser.driver.wait(function() {
      return browser.driver.getCurrentUrl().then(function(url) {
          return /success/.test(url);
}, 10000);


  Generated template for the LoginPage page.

  See for more info on
  Ionic pages and navigation.
<link href="" type="text/css" rel="stylesheet">


    <ion-navbar transparent>


  <ion-content padding>

    <div class="align">

             <ion-list >
                   <ion-input id="username" type="email"      placeholder="Email" [(ngModel)]=""></ion-input>
                   <ion-input id ="password" type="password" placeholder="Password" [(ngModel)]="user.password"></ion-input>
              <button  ion-button full clear color="light" (click)="login(user)">Login</button>
              <button ion-button block round outline color="light" (click)="register()">Register</button>


        font-size: 3em;
        text-align: center;
        font-family: Sacramento;
        font-style: cursive;
        color: white;
        text-shadow: 4px 4px 4px rgba(0,0,0,0.1); 


import { browser, by, element } from 'protractor';

export class LoginPage {
  return browser.get('/login');
 get usernameLabel() {
  return element(by.css('.login-field:nth-child(1) label'));

 getEmailTextbox() {
  return element('username'));
 get passwordLabel() {
  return element(by.css('.login-field:nth-child(2) label'));
getPasswordTextbox() {
 return element('password'));

   export class Page {

    return browser.get('/login');

    getTitle() {
   return browser.getTitle();

   getPageOneTitleText() {
   return element(by.tagName('page-page1')).element(by.tagName('ion-  title')).element(by.css('.toolbar-title')).getText();

  goToLoginPage(): any{
   let LoginPage = require("../src/pages/login/login").default;
   return new LoginPage();

   return element('username'))

   return element('password'))


1 Answers

Community On

If you get this error fro Protractor

Error:- Failed: no such element: Unable to locate element: {"method":"css selector","selector":"*[id="user1"]"}

and you are using this locator that is not possible because you are using id= username and your protractor return "selector":"*[id="user1"]" that is not believable.

 var userNameField = browser.driver.findElement('username'));

 var userPassField = browser.driver.findElement('password'));

you are using protractor then you must user protractor locator protractor provides the awesome locator class then you must use protractors locators.

you can use element(by.model('')) that is best suitable for your test.