码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-08-08 17:32:06      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:

很多时候我们遇到多层级的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即可;
 

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

标签:

原文地址:http://www.cnblogs.com/lingling99/p/5750134.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!