多浏览器代码优化
除了 Firefox、chrome、IE 以外,可看到 opera 、Safari 等也可支持,这边不一一介绍了,如果想要了解,可google。
可写一个 .py 来启动浏览器,测试代码仅需 import 即可。
1 # !/usr/bin/env python
2 # -*- coding:utf-8 -*-
3
4 from os import environ
5 from selenium import webdriver
6
7 ff = webdriver.Firefox() # Firefox
8 ff.maximize_window() # full-window
9
10 chromedriver = "C:UserssisiAppDataLocalGoogleChromeApplicationchromedriver.exe"
11 environ["webdriver.chrome.driver"] = chromedriver
12 chrome = webdriver.Chrome(chromedriver) # Chrome
13 chrome.maximize_window() # full-window
14
15 iedriver = "C:Program FilesInternet ExplorerIEDriverServer.exe"
16 environ["webdriver.ie.driver"] = iedriver
17 ie = webdriver.Ie(iedriver) # IE
18 ie.maximize_window() # full-window
19
20
21 ''' Your testing code should be here '''
22
23 TEST_URL = "
http://www.baidu.com"
24
25 ff.get(TEST_URL)
26 chrome.get(TEST_URL)
27 ie.get(TEST_URL)