zoukankan      html  css  js  c++  java
  • Selenium的崎岖定位问题

    一、iframe框架定位问题

    1、单个框架切换

    1)切进框架

    -- 可根据iframe的name或者ID定位;

    举例:driver.switch_to.frame(‘frame’);

    -- 根据元素定位,用元素的className或者css来定

    如果没有name或者ID就根据元素对象到iframe元素;

    举例:

     frame=driver.find_element(By.XPATH,'//iframe[@class="ke-edit-iframe"]')

     driver.switch_to.frame(frame)

    --根据iframe的index来定位

     举例:driver.switch_to.frame (0); 表示第1个iframe

    2)切出框架

    框架元素识别完之后,一定要记得切回默认页面

    driver.switch_to.default_content()   #切出当前框架,返回默认页面

    2、多个框架切换

    1)通过索引定位

    # 通过索引定位区分

    # 第一层框架

    driver.switch_to.frame(0)  # 通过索引定位,通过插件数iframe的个数,从0开始

    driver.find_element_by_xpath('//a[@id="switcher_plogin"]').click()

    # 第二层框架

    driver.switch_to.frame(1)

    driver.find_element_by_xpath('//input[@id="login_button"]').click()

    #返回上层框架

    driver.switch_to.parent_frame()

    #返回默认页

    driver.switch_to.default_content()

    2)通过元素定位

    # 第一层框架

    driver.switch_to.frame('ID或name')  # 也可以通过元素对象定位

    driver.find_element_by_xpath('//a[@id="switcher_plogin"]').click()

    # 第二层框架

    driver.switch_to.frame('ID或name')

    driver.find_element_by_xpath('//input[@id="login_button"]').click()

    #返回上层框架

    driver.switch_to.parent_frame()

    #返回默认页

    driver.switch_to.default_content()

    待更新......

  • 相关阅读:
    PostgreSQL杂记页
    程序员给女朋友周年纪念的浪漫
    实现乐鑫esp8266的无线OTA升级,实现远程在线升级固件
    XAOP的使用示范例子
    XPage的使用示范例子
    Python手势识别与控制
    Python人体肤色检测
    基于Opencv自带BP网络的车标简易识别
    iOS 自定义转场动画
    Python实时语音识别控制
  • 原文地址:https://www.cnblogs.com/HMeier/p/12682966.html
Copyright © 2011-2022 走看看