Entering values into input fields?

2,011 views
Skip to first unread message

Rifath Rashid

unread,
Aug 11, 2017, 4:10:23 PM8/11/17
to NightwatchJs
I'm trying to test a form that I have on a page.  I'm using the setValue() method, using the id of the input tag and the value I want to be entered into that input field.  This works great with anything that has input type "text".  However, for any input field that has type "email" or "tel", it doesn't fill anything.  I've even tried to do document.getElementById().value = "desired value" ...same thing, it works for input fields with type text but not for ones with other types.  Any ideas?  
Message has been deleted
Message has been deleted

Walter

unread,
Aug 15, 2017, 7:04:25 AM8/15/17
to NightwatchJs

I'm not sure if you have tried using Classes / CSS Paths, IDs, or XPATHs but that might be what you are looking for. I wrote a simple

test {below} that navigates to google and performs a search for 'Nightwatch.JS'. Save the code below into a file (google.js) and run it.

This should help you and others here understand how to use to use xpaths within your Nightwatch tests. 

Don't forget to comment out one of the setValue and click commands before running the test or it will fail. 

Please let me know if this helps or is somehow not clear. 


module.exports = {
'GOOGLE SEARCH FOR NIGHTWATCH.JS' : function (browser) {
browser

// REMOVE ONE OF THE SET VALUES BELOW BEFORE RUNNING
// USING CSS PATH
.setValue('input#lst-ib.gsfi', "Nightwatch.JS")
// OR USING XPATH
.setValue('xpath', '//*[@title="Search"]', "Nightwatch.JS")
// REMOVE ONE OF THE CLICKS BELOW BEFORE RUNNING
// CLICK THE 'GOOGLE SEARCH' BUTTON USING VALUE
.click('xpath', '//*[@value="Google Search"]')
// CLICK THE 'GOOGLE SEARCH' BUTTON USING NAME
.click('xpath', '//*[@name="btnK"]')
// ASSERT THE FIRST LIST ITEM READS 'Nightwatch.js | Node.js powered End-to-End testing framework'
.assert.containsText("#rso > div > div > div:nth-child(1) > div > div > h3 > a", "Nightwatch.js | Node.js powered End-to-End testing framework", "Google search was successful!")
.end();
}
};

Rody Bothe

unread,
Aug 16, 2017, 5:35:47 PM8/16/17
to NightwatchJs
selectConfirmEmail: {
selector: '[name="confirmemail"]'
},
selectAddress: {
selector: '[name="address"]'

Just use: '[name="address"]' 

SetValue('@selectAddress', blabla)

Eric Mumford

unread,
Aug 16, 2017, 11:18:34 PM8/16/17
to NightwatchJs
Hone your CSS identifiers to be accurate.

Eric Mumford

unread,
Aug 18, 2017, 12:38:11 AM8/18/17
to NightwatchJs
setValue() should perform well regardless of input type. What error are you seeing? What selector identifiers are you using?
Reply all
Reply to author
Forward
0 new messages