首页 > 编程语言 > 详细

python+selenium元素定位04——浏览器多窗口处理

时间:2020-04-09 10:22:54      阅读:80      评论:0      收藏:0      [点我收藏+]

1、获得新窗口句柄值

    每个窗口都会产生一个独立的句柄、随机的字符串(由字母和数字组成),每次打开句柄值都会变化

    

import os
import time
from selenium import webdriver
from selenium.webdriver.common.by  import By
from selenium.webdriver.support.select import Select

current = os.getcwd()
chrome_driver_path =os.path.join(current,../webdriver/chromedriver)
page_path = os.path.join(current,../pages/element_samples.html)    #本地html文件
driver = webdriver.Chrome(executable_path=chrome_driver_path)
driver.implicitly_wait(2)
driver.get(file://+page_path)
handle =driver.current_window_handle
print(当前窗口handle值:,handle)
e =driver.find_element(By.XPATH,//select[@name="jumpMenu"])
Select(e).select_by_visible_text(开封教育网)
time.sleep(3)
handles =driver.window_handles
print(所有的handle值,handles)
time.sleep(1)
driver.quit()

 

python+selenium元素定位04——浏览器多窗口处理

原文:https://www.cnblogs.com/miaoxiaochao/p/12639981.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!