zoukankan      html  css  js  c++  java
  • 多窗口切换及截图

    获得当前窗口句柄:b.current_window_handle

    获取所有窗口的句柄:b.window_handles

    切换到相应的窗口:switch_to_window()

    # coding:utf-8
    from selenium import webdriver
    from time import sleep
    import time
    b=webdriver.Chrome()
    b = webdriver.Chrome()
    #b.implicitly_wait(10)
    b.maximize_window()
    b.get('http://wenku.baidu.com/')
    # 获取当前窗口句柄
    current_handle = b.current_window_handle
    # 打印当前窗口句柄
    print current_handle
    b.find_element_by_name('word').send_keys('userName')
    b.find_element_by_link_text(u'小学').click()
    all_handle = b.window_handles
    print all_handle
    for handle in all_handle:
    if handle != current_handle:
    b.switch_to.window(current_handle)
    # 切换到原来的窗口
    b.find_element_by_xpath("//*[@id='wk-all-cate']/dl[1]/dd/a[4]").click()
    b.switch_to.window(current_handle)
    b.find_element_by_name('word').clear()
    b.find_element_by_name('word').send_keys('lisi')
    sleep(5)
    #截图操作
    b.get_screenshot_as_file(r'D:123.png')

    b.quit()



    截图

    # b = webdriver.Chrome()
    # b.implicitly_wait(10)
    # b.maximize_window()
    # b.get("http://www.baidu.com")
    # b.get_screenshot_as_file('./baidu.jpg')
    # #img_ele = b.find_element_by_id('su')
    # #img_ele.screenshot(r".//test.png")
    # sleep(3)
    # b.quit()









  • 相关阅读:
    极光推送的的栗子
    老师oracle讲义第五天
    oracle学习第五天
    ajax使用
    jstl标签的使用
    json使用
    jsp的el表达式使用
    老师oracle讲义第三天
    oracle学习第一天
    oracle学习第二天
  • 原文地址:https://www.cnblogs.com/huaihe/p/11204383.html
Copyright © 2011-2022 走看看