Selenium多层级的iframe中元素的定位

发表于:2016-8-22 09:26

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:Ling99    来源:51Testing软件测试网采编

  很多时候我们遇到多层级的iframe就会想各种方法去获取iframe中的元素,但其实很简单就可以做到的,就是一级一级获取就可以了,获取至你需要的那个层级即可,下面看下实际的案例;
<frame src="" id="index_main" name="main" scrolling="Yes" noresize="noresize">
<iframe id="Editor1" src="" frameborder="0" scrolling="no" >
<iframe id="eWebEditor" width="100%" height="100%" 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即可;
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号