zoukankan      html  css  js  c++  java
  • python + selenium <四>

    层级定位

    • swich_to_alert
    • swich_to_frame
    • swich_to_window

    1. driver.switch_to_alert().accept()#最简单,直接点击确定关闭弹出提示框

    2.swich_to_frame

    •   要处理的frame有唯一的Id或name还好,直接:driver.switch_to_frame("frame1");
    •   若是既没ID也没name,首先需要解决定位的问题,python中定位有很多方法,我比较常用的是xpath,
    WebElement frame=driver.findElement_by.xpath( "//div[@class=='XXX']/a" );
    driver.switch_to_frame(frame);

    3.swich_to_window

    now_handle = driver.current_window_handle #获取当前打开窗口句柄
    all_handles = driver.window_handles #获取浏览器已打开所有窗口句柄
    for handle in all_handles:
      if handle!=now_handle:
        driver.switch_to_window(handle)
    driver.switch_to_window(now_handle)
     
  • 相关阅读:
    iOS基础
    iOS基础
    iOS基础
    iOS基础
    iOS基础
    iOS基础
    iOS基础
    iOS基础
    iOS基础
    iOS基础
  • 原文地址:https://www.cnblogs.com/hito/p/4514265.html
Copyright © 2011-2022 走看看