Created
August 5, 2016 09:17
-
-
Save ivan-kleshnin/814f6b9d7d0057cd1e9e5c33acf81312 to your computer and use it in GitHub Desktop.
NightmareJS `clickNth` custom action
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Nightmare.action("clickNth", function (selector, n, done) { | |
debug(".clickNth() on " + selector + ":" + n) | |
this.evaluate_now(function (selector, n) { | |
document.activeElement.blur() | |
var element = document.querySelectorAll(selector)[n] | |
if (!element) { | |
throw new Error('Unable to find element by selector: ' + selector) | |
} | |
var event = document.createEvent('MouseEvent') | |
event.initEvent('click', true, true) | |
element.dispatchEvent(event) | |
}, done, selector, n) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment