zoukankan      html  css  js  c++  java
  • Selenium多层级的iframe中元素的定位

    很多时候我们遇到多层级的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即可;
     
  • 相关阅读:
    TreeSet和TreeMap中“相等”元素可能并不相等
    求众数——摩尔投票
    5802. 统计好数字的数目
    快速幂
    LCP 07.传递消息
    332. 重新安排行程(欧拉回路问题)
    126. 单词接龙 II
    879. 盈利计划
    287. 寻找重复数
    239. 滑动窗口最大值
  • 原文地址:https://www.cnblogs.com/lingling99/p/5750134.html
Copyright © 2011-2022 走看看