打开多个浏览器并且切换浏览器

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2018/5/22 11:49
# @Author  : 清心
# @File    : openBrower.py
from selenium import webdriver
import time


# opts = webdriver.ChromeOptions()
# opts.binary_location(value='E:\\Google_Chrome\\chromedriver.exe')
# browser = webdriver.Chrome(chrome_options=opts)

# browser = webdriver.Chrome("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe")
browser = webdriver.Chrome()
browser.get('https://www.baidu.com')
browser.execute_script('window.open()')
print(browser.window_handles)
time.sleep(2)
browser.switch_to.window(browser.window_handles[1])
browser.get('https://www.taobao.com')
time.sleep(1)
browser.switch_to.window(browser.window_handles[0])
browser.get('https://www.cnblogs.com/zhaof/p/6953241.html')
time.sleep(2)
browser.execute_script('window.open()')
time.sleep(2)
print("开始选择窗口了。。。。。。")
b = browser.window_handles
browser.switch_to.window(b[2])
time.sleep(1)
browser.switch_to.window(b[1])
time.sleep(1)
browser.switch_to.window(b[0])
time.sleep(1)
browser.switch_to.window(b[2])
print("选择完毕,开始填写网址")
time.sleep(2)
browser.get("https://blog.csdn.net/Sily_Z")
time.sleep(3)

browser.quit()

仅供自己记录,如有帮助,万分高兴

猜你喜欢

转载自blog.csdn.net/sily_z/article/details/80734465