zoukankan      html  css  js  c++  java
  • selenium 多窗口切换

    selenium 多窗口切换

    知识点:

    1、current_window_handle:获取当前窗口句柄

    2、window_handles:返回所有窗口的句柄到当前会话

    3、switch_to.window():用于切换到相应的窗口。  与switch_to.frame()类似。

      switch_to.window()是用于不同窗口的切换。switch_to.frame()是用于不同表单的切换。

    示例;

    #selenium 窗口切换
    from selenium import webbrowser
    import time
    
    driver = webdriver.Firefox()
    driver.implictly_wait(10)
    driver.get("http://www.baidu.com")
    
    #获取百度搜索框的句柄
    search_windows = driver.current_window_handle
    
    driver.find_element_by_link_text('登录').click()
    driver.find_element_by_link_text("立即注册").click()
    
    #获得当前打开得句柄得窗口
    current_window_handles = driver.window_handles
    
    #进入注册窗口
    for handle in all_handles:
        if handle != search_windows:
            driver.switch_to.window(handle)
            print('NOW register window.')
            driver.find_element_by_name('account').send_keys('username')
            driver.find_element_by_name('password').send_keys('password')
            time.sleep(2)
    
    driver.quit()
    

      

  • 相关阅读:
    IO流
    java的反射机制
    docker下安装mysql
    makefile
    python轻量级orm
    MySQLdb与sqlalchemy的简单封装
    python网络socket编程
    解决mysqldb查询大量数据导致内存使用过高的问题
    sqlalchemy根据数据库结构生成映射的实体
    centos7构建python2.7常用开发环境
  • 原文地址:https://www.cnblogs.com/aszeno/p/10317841.html
Copyright © 2011-2022 走看看