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

      

  • 相关阅读:
    js函数与DOM
    js流程控制语句与数组
    js基础语法与表达式
    CSS
    注解使用IDEA的Filter注解模板
    JSP小结
    JSP的九大内置对象
    Mac上Sublime常用快捷键
    git cherry-pick: failed to refresh the index
    c++11之后类中定义常量的最好方法
  • 原文地址:https://www.cnblogs.com/aszeno/p/10317841.html
Copyright © 2011-2022 走看看