private Map < String , String > getGeneratedHtmlSourceRecursive ( FrameNode currentFrame , String currFrameId ) throws Exception { Map < String , String > frames = new HashMap < String , String > ( ) ; if ( ! currentFrame . isRoot ( ) ) { wd . switchTo ( ) . defaultContent ( ) ; Stack < FrameNode > framesToSelect = new Stack < FrameNode > ( ) ; FrameNode currFrame = currentFrame ; while ( currFrame . getParent ( ) != null ) { framesToSelect . push ( currFrame ) ; currFrame = currFrame . getParent ( ) ; } while ( ! framesToSelect . isEmpty ( ) ) { FrameNode fn = framesToSelect . pop ( ) ; wd . switchTo ( ) . frame ( fn . getFrame ( ) ) ; } } else { wd . switchTo ( ) . defaultContent ( ) ; } // Add current frame frames . put ( currFrameId , wd . getPageSource ( ) ) ; int iframeCount = wd . findElements ( By . xpath ( "//iframe" ) ) . size ( ) ; if ( iframeCount == 0 ) { return frames ; } for ( int i = 1 ; i <= iframeCount ; i ++ ) { if ( ! currentFrame . isRoot ( ) ) { wd . switchTo ( ) . defaultContent ( ) ; Stack < FrameNode > framesToSelect = new Stack < FrameNode > ( ) ; FrameNode currFrame = currentFrame ; while ( currFrame . getParent ( ) != null ) { framesToSelect . push ( currFrame ) ; currFrame = currFrame . getParent ( ) ; } while ( ! framesToSelect . isEmpty ( ) ) { FrameNode fn = framesToSelect . pop ( ) ; wd . switchTo ( ) . frame ( fn . getFrame ( ) ) ; } } else { wd . switchTo ( ) . defaultContent ( ) ; } FrameNode nextFrame = new FrameNode ( currentFrame , By . xpath ( "(//iframe)[" + i + "]" ) , this . getWrappedDriver ( ) . findElement ( By . xpath ( "(//iframe)[" + i + "]" ) ) ) ; String nextFrameId = currFrameId . substring ( 0 , currFrameId . length ( ) - 1 ) + "-" + i + "]" ; // Recursively add next frames frames . putAll ( getGeneratedHtmlSourceRecursive ( nextFrame , nextFrameId ) ) ; } return frames ; }
Gets the current html source from the dom for the every frame in the current window recursively