浏览器驱动
# 打开浏览器并最大化 def open_browser(browser): #无窗口模式 #option = webdriver.ChormeOptions() #option.add_argument('headless') global driver, waitUtil try: if browser.lower() == "ff": driver = webdriver.Firefox() driver.maximize_window() print("火狐窗口启动成功") elif browser.lower() == "ie": driver = webdriver.Ie() driver.maximize_window() print("IE窗口启动成功") elif browser.lower() == "gg": driver = webdriver.Chrome() driver.maximize_window() print("谷歌窗口启动成功") elif browser.lower() == "eg": #版本和驱动匹配存在问题,edge浏览器绑定win10系统后,浏览器版本无法回退 #当前版本与内核版本不匹配所以尚不可调用 driver = webdriver.Edge() driver.maximize_window() print("Edge窗口启动成功") elif browser.lower() == "op": driver = webdriver.Opera() driver.maximize_window() print("Opera窗口启动成功") elif browser.lower() == "360": exe_data = r'D:\360极速浏览器\install\360Chrome\Chrome\Application\360chrome.exe' chrome_options = Options() chrome_options.binary_location = exe_data driver = webdriver.Chrome(chrome_options=chrome_options) driver.maximize_window() print("360窗口启动成功") elif browser.lower() == "sg": #搜狗浏览器默认光标不在地址栏,可以设置默认打开地址,即可以不用加载网址 #当前版本与内核版本不匹配所以尚不可调用 exe_data = r'D:\搜狗浏览器\install\SogouExplorer\SogouExplorer.exe' chrome_options = Options() chrome_options.binary_location = exe_data driver = webdriver.Chrome(chrome_options=chrome_options) driver.maximize_window() print("搜狗窗口启动成功") elif browser.lower() == "qq": exe_data = r'D:\qq浏览器\install\QQBrowser\QQBrowser.exe' chrome_options = Options() chrome_options.binary_location = exe_data driver = webdriver.Chrome(chrome_options=chrome_options) driver.maximize_window() print("QQ窗口启动成功") else: print("此自动化框架仅支持Firefox,IE,Chrome,Opera,360,qq浏览器") except Exception as e: raise e else: waitUtil = WaitUnit(driver) #driver创建之后,创建等待类实例对象 # 关闭浏览器 def quit_browser(): try: driver.quit() print("关闭当前浏览器成功") except Exception as e: raise e #关闭窗口 def close_browser(): try: driver.close() print("关闭当前窗口成功") except Exception as e: raise e #关闭所有窗口 def close_all(): try: driver.close_all() print("关闭所有窗口成功") except Exception as e: raise e
心之所向无人可挡