Kode_12
Kode_12

Reputation: 4798

How can I grab an element by Id, using nightwatch.js?

New to nightwatch.js. While writing my first tests, I cannot find conventional ways to 'grab' elements that I want to test using assertions.

Say I have an input field:

 <input id="myInput"></input>

How can I create a selector for this?

I've tried the following, which definitely is the wrong syntax:

 module.exports = {  
  'Initial Test': function(browser) {
    browser
      .url('http://127.0.0.1:51260/index.html') //insert your local path 
      .waitForElementVisible('body')
      .assert.title('First Test')
      .expect.element('input[id=myInput]').to.be.visible;

      browser.end();
  }
};

Upvotes: 4

Views: 6281

Answers (1)

Naveen Kumar R B
Naveen Kumar R B

Reputation: 6398

try

   module.exports = {  
  'Initial Test': function(browser) {
    browser
      .url('http://127.0.0.1:51260/index.html') //insert your local path 
      .waitForElementVisible('body')
      .assert.title('First Test')
      .waitForElementVisible('input[id=myInput]', 1000)
      .setValue('input[id=myInput]', 'write something')
      .end();
  }
};

Reference:

  1. http://nightwatchjs.org/guide

Upvotes: 3

Related Questions