Sample Code for multi-window processing in selenium python browser, seleniumpython
This article focuses on the multi-window processing of selenium python browsers and shares the operation instance Code as follows:
#! /Usr/bin/python #-*-coding: UTF-8-*-_ author _ = 'zuoanvip '# during the test, multiple browser windows may occur, at this time, we can use the window handle to operate the elements of different windows from selenium import webdriverimport osimport timedriver = webdriver. firefox () driver. get ('HTTP: // www.baidu.com ') # obtain the handle of the current window nowwhandle = driver. current_window_handle # Open the new registration window driver. find_element_by_name ('tg _ reg '). click () # obtain the handle allhandles = driver for all windows. window_handles # cyclically determine whether the window is the current window for handle in all Handles: if handle! = Nowwhandle: driver. switch_to_window (handle) print 'now register window! '# Switch to the mailbox registration tag driver. find_element_by_id ('mailregtab '). click () time. sleep (5) driver. close () # return the original window driver. switch_to_window (nowwhandle) driver. find_element_by_id ('kw '). send_keys (u'registered successfully') driver. quit ()
The execution process is as follows: first obtain the handle of the current window through nowhandle, then open the registration window, get the handle of all windows through allhandles, traverse the handle cyclically, and determine whether the window is nowhandle, if not, obtain the handle of the current window, operate on the elements of the current page, and return nowhandle.
Summary
The above is all the content about the example code for multi-window processing in selenium python browser. I hope it will be helpful to you. If you are interested, you can continue to refer to other related topics on this site. If you have any shortcomings, please leave a message. Thank you for your support!