Scenes
start the browser
Launching the browser when using webdriver for testing is undoubtedly a necessary pre-work;
close the browser
Closing the browser when the script finishes running or when the test code finishes is as natural as clearing the table after eating.
There are two ways to close the browser:
- close method
- quit method
The close method closes the current browser window, and the quit method not only closes the window, but also completely exits the webdriver and releases the connection with the driver server. So simply put, quit is a more thorough close, and quit will release resources better, which is suitable for obsessive-compulsive disorder and perfectionists.
code
#!/usr/bin/env python # -*- coding:utf-8 -*- ''' Created on 2018/5/9 9:55 @author: Jeff Lee @file: start close browser.py ''' from selenium import webdriver import time print('Open browser') client = webdriver.Firefox() time.sleep(2) print('close the browser') client.quit() #client.close()
Reference http://www.cnblogs.com/nbkhic/tag/%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95/