您的位置:軟件測試 > 開源軟件測試 > 開源功能測試工具 > Selenium
Selenium多層級的iframe中元素的定位
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2016/8/22 9:54:02 ] 推薦標(biāo)簽:功能測試 selenium

  很多時(shí)候我們遇到多層級的iframe會(huì)想各種方法去獲取iframe中的元素,但其實(shí)很簡單可以做到的,是一級一級獲取可以了,獲取至你需要的那個(gè)層級即可,下面看下實(shí)際的案例;
<frame src="" id="index_main" name="main" scrolling="Yes" noresize="noresize">
<iframe id="Editor1" src="" frameborder="0" scrolling="no" >
<iframe id="eWebEditor" width="" height="" scrolling="yes" frameborder="0" src="">
<input type="text" id="TeacherTxt" name="Teacher" size="12" maxlength="12" >
</iframe>
</iframe>
</iframe>
  示例:
@Test
public void phoneLogin() throws Exception{
WebDriver chrome = new ChromeDriver();
chrome.switchTo().frame("index_main");
chrome.switchTo().frame("Editor1");
chrome.switchTo().frame("eWebEditor");
chrome.findElement(By.id(" TeacherTxt")).sendKeys("測試Iframe");
chrome.switchTo().defaultContent();
}
  注意:后只需要退出一次iframe即可;
 

軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd