I need help with a problem I'm facing, and am sure node-horseman can handle it.
I'm trying to accept a "window.confirm" alert and tried many things without success. Basically, after clicking on a button, I want to be able to "accept" the confirm message using horseman.
Going through the docs, I found this:
.at(event, callback) Respond to page events with the callback.
.at('confirm', function(msg) {
return msg === 'Like this?' ? true : false;
})
Nevertheless, when I put the .at like this, before any .open
horseman
.at('confirm', function(msg) {
return msg === 'Do you accept?' ? true : false;
})
I get an error saying:
TypeError: horseman.at is not a function
What I'm looking for: a way to accept a window.confirm using node-horseman.
Any help will be really appreciated!
Reading this answer helped me solve the issue.
Instead of using .at I did the following:
And this worked!
Basically, I override the window.confirm function for the next time it is called, and restore it to the previous value during the execution.
I hope this will help others as well.