zoukankan      html  css  js  c++  java
  • jQuery火箭图标返回顶部代码

    在 web 应用中经常会出现 iframe 嵌套的应用,假设页面上有 A、B 两个 iframe,其中 B 在 A 内,那么定位 B 中的内容则需要先到 A,然后再到 B。

    iframe 中实际上是嵌入了另一个页面,而 webdriver 每次只能在一个页面识别,因此需要用 switch_to.frame 方法去获取 iframe 中嵌入的页面,对那个页面里的元素进行定位。

    常用方法如下:

    # 先找到到 iframe1(id = f1)

    driver.switch_to_frame("f1")

    # 再找到其下面的 iframe2(id =f2)

    driver.switch_to_frame("f2")

    # 下面就可以正常的操作元素了

    driver.find_element_by_id("xx").click()

    例:要求定位id="TeacherTxt"

    <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>
    代码如下:
    driver.switch_to_frame("inden_main")
    driver.switch_to_frame("Editor1")
    driver.switch_to_frame("eEebEditor")
    driver.find_element_by_id("TeacherTxt").send_keys('tester')
     

    注:若页面中只有一个iframe且这个iframe为js加载的,那么只需要switch_to_frame(‘id’)即可

    ---------------------------------------------------------------------------------------------------------------------------------

    有可能嵌套的不是框架,而是窗口,还有针对窗口的方法:switch_to_window 

    用法与switch_to_frame 相同: 

    driver.switch_to_window("windowName")

  • 相关阅读:
    Flask 5 模板1
    Flask 4 拓展
    Python学习札记(二十四) 函数式编程5 返回函数
    Python学习札记(二十三) 函数式编程4 sorted
    Docker:Err http://archive.ubuntu.com trusty InRelease & E: Unable to locate package [name] 问题
    解决 docker: Error response from daemon: ... : net/http: TLS handshake timeout.
    Ubuntu 安装Docker
    Flask 3 程序的基本结构2
    Flask 2 程序的基本结构1
    Flask 1 Introductory Chapter
  • 原文地址:https://www.cnblogs.com/cnkemi/p/6137162.html
Copyright © 2011-2022 走看看