I am using Page Objects in nightwatch. I am trying to use .element() or .elements and having issues.
'use strict';
var paths = require('../paths.js');
module.exports = {
url: paths.launchPath,
elements: {
email: {
selector: 'input[placeholder^="Username"]'
},
password: {
selector: 'input[placeholder^="Password"]'
},
signInButton: {
selector: '.btn.btn-lg.btn-orange.pull-right'
},
homeIcon: {
selector: '.navbar-brand'
},
studyTab: {
selector: 'html/body/div[2]/ul[1]/li[2]/a',
locateStrategy: 'xpath'
},
studyListTable: {
selector: 'html/body/div[4]/div/div[2]',
locateStrategy: 'xpath'
},
studyListTable1: {
selector: 'html/body/div[4]/div/div[2]/div[1]',
locateStrategy: 'xpath'
},
studyListTable2: {
selector: 'draft_studies'
// locateStrategy: 'xpath'
},
loadingAnnimation: {
selector: '.loading'
}
},
commands: [{
signIn: function() {
return this
.waitForElementPresent('@signInButton', 1000)
.setValue('@email', 'mpanda')
.setValue('@password', 'Login123')
.click('@signInButton')
.waitForElementPresent('@homeIcon', 50000)
.assert.elementPresent('@homeIcon', 'Home Icon Present')
.waitForElementPresent('@studyTab', 50000)
.click('@studyTab')
.waitForElementPresent('@studyListTable', 20000)
.waitForElementPresent('@studyListTable1', 20000)
.element('css selector', '@studyListTable', function(result) {
console.log("Element is ... " + result);
})
}
}]
};
I am having issues accessing .element() in the Page Object JS, but if I do browser.element() in the Test JS it is working well for me.
Can someone please let me know if we can access .element(), .elements() etc( anything from "Web Driver Protocol" ). Right now its failing with an error "TypeError: this.waitForElementPresent(...).setValue(...).setValue(...).click(...).waitForElementPresent(...).assert.elementPresent(...).waitForElementPresent(...).click(...).waitForElementPresent(...).assert.elementPresent(...).waitForElementPresent(...).assert.elementPresent(...).element is not a function".