#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @File : handles.py
# @Software: PyCharm
import time
from selenium import webdriver
url = 'http://cd.ganji.com/'
browser = webdriver.Firefox()
browser.get(url)
time.sleep(5)
# 获取当前页面的窗口句柄
handle = browser.current_window_handle
print(handle)
# 获取所有窗口句柄
browser.find_element_by_link_text('成都招聘').click()
handles = browser.window_handles
print(handles)
# 方法一:判断句柄是否与首页相等
for i in handles:
if i != handle:
browser.switch_to.window(i)
print(browser.title)
browser.close()
browser.switch_to.window(handle)
print(browser.title)
# 方法二:直接获取list列表里面的值,取值handles[i]
# browser.switch_to.window(handles[0])
# print(browser.title)
# 退出
browser.quit()
selenium窗口切换
最新推荐文章于 2023-04-07 09:53:53 发布