Created
April 21, 2016 09:54
-
-
Save sdussaut/ce45effa920d4aceb92a6bf57c19ca6d to your computer and use it in GitHub Desktop.
Add focus action support to NightmareJS.
This file contains 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
var Nightmare = require( 'nightmare' ); | |
/** | |
* Add focus action to NightmareJS | |
* | |
* Usage: | |
* .focus( selector ) => .focus( '.myClass' ) | |
*/ | |
Nightmare.action( 'focus', function ( selector, done ) { | |
this.evaluate_now(( selector ) => { | |
document.activeElement.blur(); | |
var element = document.querySelector( selector ); | |
element.focus(); | |
}, done, selector ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment