java selenium (十四) 處理Iframe 中的元素
什麽是iframe
iframe 就是HTML 中,用於網頁嵌套網頁的。 一個網頁可以嵌套到另一個網頁中,可以嵌套很多層。
selenium 中提供了進入iframe 的方法
// 進入 id 叫frameA 的 iframe dr.switchTo().frame("frameA");
// 回到主窗口 dr.switchTo().defaultContent();
main.html
<html> <head> <title>FrameTest</title> </head> <body> <div id="id1">this is main page‘s div!</div> <input type="text" id="maininput" /> <br/> <iframe id="frameA" frameborder="0" scrolling="no" style="left:0;position:absolute;" src="frame.html"></iframe> </body> </html>
frame.html
<html> <head> <title>this is a frame!</title> </head> <body> <div id="div1">this is iframes div,</div> <input id="iframeinput"></input> </body> </html>
selenium 代碼
public static void testIframe(WebDriver driver) { driver.get("E:\\StashFolder\\[email protected]
java selenium (十四) 處理Iframe 中的元素