2

NW noobie here. How can I increase/decrease the value of a range element via Nighwatch?

I tried sendKeys to no avail.

Thanks in advance.

Sua Morales
  • 894
  • 10
  • 21

2 Answers2

1

the way that worked for me is executing javascript in the browser to change the value of input=range, and then trigger the change event

   .execute(function(data) {
        try {
            // statements

            p = document.querySelector("input[type='range']");
            p.value = 41;
            event = document.createEvent("HTMLEvents");
            event.initEvent("change", true, true);
            p.dispatchEvent(event);
        } catch(e) {
            // statements
            console.log(e);
        }


        return true;
    }, [], function(result) {

    });
David Torroija
  • 593
  • 5
  • 17
  • This didn't work for me fully. It did move the slider but did not trigger the change event. Is that browser specific? – climboid Mar 14 '17 at 16:21
  • yes it is browser specific here you have a complete guide of event trigger for all browsers in this question http://stackoverflow.com/questions/2490825/how-to-trigger-event-in-javascript – David Torroija Mar 15 '17 at 21:16
0

I managed to get it to work by triggering a drag event on the input type range

climboid
  • 6,932
  • 14
  • 44
  • 71
  • I realize this was answered 4 years ago but I'm trying something similary ... using try/catch in an .execute function ... but it doesn't seem like try/catch is working. Specifically, where there is an error it is not logged to the console. Clarification - the error IS logged but it goes to the web console rather than to the console in my IDE (VSCode). – John Kretschmann Mar 23 '21 at 21:21