参考原文:http://blog.csdn.net/gz_testing/article/details/71251901
http://blog.csdn.net/u011159607/article/details/53887273
浏览器支持多窗口打开,但是打开一个新的窗口后,selenium不会自动跳转至新的窗口,需要自己切换
1. driver.window_handles 获取当前浏览器的所有窗口,此时windows 为一个数组,windows = [窗口1,窗口2,窗口3....]
切换为最新打开的窗口:driver.switch_to.window(windows[-1])
切换为最初打开的窗口: driver.switch_to.window(windows[0])
windows = driver.window_handles
driver.switch_to.window(windows[-1])
2. window_1 = driver.current_window_handle 获得打开的第一个窗口
all_windows = driver.window_handles #获得所有打开的窗口
for current_window in all_windows: 循环是为了切换到最新的窗口
if current_window != window_1:
driver.switch_to.(current_window)