from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
import time
class SeleniumDriver:
def __init__(self,browser):
"""判断打开浏览器"""
self.browser = browser
if self.browser == 'firefox':
self.driver = webdriver.Firefox()
elif self.browser == 'chrome':
self.driver = webdriver.Chrome()
elif self.browser == 'ie':
self.driver = webdriver.Ie()
else:
self.driver = webdriver.Edge()
time.sleep(2)
def get_url(self,url):
if self.driver !=None:
if 'http://' in url:
self.driver.get(url)
else:
print('你的url有问题!')
else:
print("case失败")
def handle_windows(self,*args):
"""判断浏览器操作"""
value = len(args)
if value == 1:
if args[0] == 'max':
self.driver.maximize_window()
elif args[0] == 'mix':
self.driver.minimize_window()
elif args[0] == 'back':
self.driver.back()
elif args[0] == 'go':
self.driver.forward()
else:
self.driver.refresh()
elif value == 2:
self.driver.set_window_size(args[0],args[1])
else:
print('你传递的参数有问题!')
time.sleep(2)
self.driver.quit()
selenium_driver = SeleniumDriver('chrome')
selenium_driver.handle_windows('max')