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









  • 相关阅读:
    2018.9.22 Bubble Cup 11-Finals(Online Mirror,Div.2)
    2018.9.21 Codeforces Round #511(Div.2)
    2018.9.20 Educational Codeforces Round 51
    解题:USACO12OPEN Bookshelf
    解题:CF983B pyramid
    1214. 许可证密钥格式
    1212. 最大连续1的个数
    1270. 勒索信
    1250. 第三大的数
    1218. 补数
  • 原文地址:https://www.cnblogs.com/huaihe/p/11204383.html
Copyright © 2011-2022 走看看