nightmare icon indicating copy to clipboard operation
nightmare copied to clipboard

Looping through dynamically created form fields to add text

Open mikenewyn opened this issue 6 years ago • 1 comments

I know this is similar to some other issues but I think I am trying to do something slightly different. I have an app(similar to MadLibs) that has a number of input fields that need to be filled out, then hit a submit button. The fields are created by different "stories" and therefor have different number of fields depending on the story.

Is there a way to loop it through the dynamically created fields? Right not it is just hard-coded and because of that, it is failing since each story has a different number of inputs.

var Nightmare = require("nightmare");

var nightmare = Nightmare({ show: true });

nightmare .goto("http://localhost:8080/test") .type("#input0", "Goku") .wait(500) .type("#input1", "hardened") .wait(500)
.type("#input2", "K-Mart") .wait(500) .type("#input3", "wanderlust") .wait(500) .type("#input4", "Pokeball") .wait(500) .type("#input5", "stupidly") .wait(500) .type("#input6", "thick") .wait(500) .type("#input7", "boil") .wait(500) .type("#input8", "screwed") .wait(500) .type("#input9", "rubber") .wait(500) .type("#input10", "42") .wait(500) .type("#input11", "wanted") .screenshot("UserSave.png") .click("#submitButton") .wait(1000) .type("#userNameBox", "New User") .screenshot("BeforeSave.png") .click("#saveButton") .wait(1000) .screenshot("AfterSave.png") .wait(3000) .end() .then(function() { console.log("Took a screenshot of the inputs, resulting story and of the return page"); }) .catch(function(error) { console.error("Search failed:", error); });

mikenewyn avatar Jan 18 '19 18:01 mikenewyn

Use evaluate to run javascript code on the page and return results.

scottie avatar Mar 26 '19 07:03 scottie