public static void inject ( final WebDriver driver , final URL scriptUrl , Boolean skipFrames ) { final String script = getContents ( scriptUrl ) ; if ( ! skipFrames ) { final ArrayList < WebElement > parents = new ArrayList < WebElement > ( ) ; injectIntoFrames ( driver , script , parents ) ; } JavascriptExecutor js = ( JavascriptExecutor ) driver ; driver . switchTo ( ) . defaultContent ( ) ; js . executeScript ( script ) ; }
Recursively injects a script to the top level document with the option to skip iframes .