Snake's Home

chromedriver on mac

最近在Mac上折腾selenium, 一直都装不上chromedriver.
今天终于找到了一个方法:

automationtest

曾今尝试过用npm安装,但是速度极其慢。(换了淘宝镜像)
chromedriver

最后的步骤是:

1.

1
npm install --save selenium-webdriver@2.44.0

2.

1
npm install --save chromedriver@2.12.0

然后实验了一个小程序,就可以了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from selenium import webdriver

import time

drivers = ['HtmlUnit']

dervers_time = {
'HtmlUnit' : 0,
}
times = 50

def run_with_Chrome():
common_step(webdriver.Chrome())
'''
def run_with_FF():
common_step(webdriver.Firefox())

def run_with_IE():
common_step(webdriver.Ie())

def run_with_PhantomJS():
common_step(webdriver.PhantomJS(executable_path=r'C:\Python27\Scripts\phantomjs.exe'))

def run_with_HtmlUnit():
driver = webdriver.Remote("http://localhost:4444/wd/hub",
desired_capabilities=webdriver.DesiredCapabilities.HTMLUNIT)
common_step(driver)
'''

def common_step(driver):
driver.get('http://www.baidu.com')
ele = driver.find_element_by_id('su')
print ele.get_attribute('value')
driver.quit()

for i in range(times):
print '=============Times %s============' % i
for driver in drivers:
start = time.time()
print start
# eval('run_with_%s()'%driver)
end = time.time()
print end
elapse_time = end-start
dervers_time[driver] += elapse_time
print 'elapse for %s:%s' % (driver, elapse_time)

for k,v in dervers_time.items():
print 'avg elapse for %s in %s times:%s' % (k, times, v/times)