学习目的:
掌握WebDriver的高级应用
正式步骤:
# -*- coding:utf-8 -*-from selenium import webdriverfrom selenium.webdriver import ActionChainsfrom selenium.webdriver.support.ui import Selectfrom selenium.webdriver.common.keys import Keysfrom selenium.common.exceptions import WebDriverExceptionimport unittestimport osimport timeimport tracebackclass WebdriverAPI(unittest.TestCase): def setUp(self): # 每个用例都执行,在单个用例运行前执行 #打开浏览器 self.driver = webdriver.Chrome() def tearDown(self): #每个用例都执行,在单个用例运行后执行 #退出浏览器 self.driver.quit() def test_closeBrowserProcess(self): url = 'https://www.baidu.com/' self.driver.get(url) returnCode = os.system("taskkill /F /im " + "chrome.exe") if returnCode == 0: print("chrome process over") else: print("chrome process over fail")if __name__ == '__main__': unittest.main()