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")

  • 相关阅读:
    go excel导入Demo
    redis限流Lua脚本
    线上机器CPU与内存升高排查
    错点
    自动化运维工具——ansible详解(一)
    k8s之命令记录
    k8s之监控集群资源利用率
    根据经纬度搜索附近的人
    微信小程序直接打开h5页面
    【python3】字符串格式化
  • 原文地址:https://www.cnblogs.com/cnkemi/p/6137162.html
Copyright © 2011-2022 走看看