系统:OS X Capitan (version:10.11)
Python2.7.10: 系统自带
终端输入python --version 可以查看版本号。
Selenium:
用命令安装
sudo easy_install selenium
在用 brew install selenium的时候检测出来是brew install selenium-server-standalone,还没有弄懂两个的差别。
Chrome Version 49:官网最新
-
from selenium import webdriver
-
-
driver = webdriver.Chrome()
-
driver.get('');
脚本运行的时候出现了问题:在stack overflow上搜到了相同问题,链接
"ChromeDriver executable needs to be available in the path. " selenium.common.exceptions.WebDriverException: Message: ChromeDriver executable needs to be available in the path. Please download from http://chromedriver.storage.googleapis.com/index.html and read up at http://code.google.com/p/selenium/wiki/ChromeDriver
最初认为chrome的安装路径没有在环境变量里面,因此把(反斜杠是解析空格)
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome
加到了环境变量里面,但是仍然不成功。因此参考stack上面给出的第一个答案,并不是特别理解,因此查看了。
Follow these steps to setup your tests for running with ChromeDriver:
-
Ensure Chromium/Google Chrome is installed in a recognised location (确保浏览器安装在可识别的路径)
ChromeDriver expects you to have Chrome installed in the default location for your platform. You can also force ChromeDriver to use a custom location by setting a special capability.
-
Download the ChromeDriver binary for your platform under the section of this site()
-
Help WebDriver find the downloaded ChromeDriver executable(让WebDriver能找到ChromeDriver有两种,1或者3)
Any of these steps should do the trick:
-
include the ChromeDriver location in your PATH environment variable
-
(Java only) specify its location via the webdriver.chrome.driver system property (see sample below)
-
(Python only) include the path to ChromeDriver when instantiating webdriver.Chrome (see sample below)
-
import time
-
from selenium import webdriver
-
-
driver = webdriver.Chrome('/path/to/chromedriver') #Optional argument, if not specified will search path.
-
driver.get('');
-
time.sleep(5) # Let the user actually see
-
search_box = driver.find_element_by_name('q')
-
search_box.send_keys('ChromeDriver')
-
search_box.submit()
-
time.sleep(5) # Let the user actually see
-
driver.quit()
1.
ChromeDriver目录加入到环境变量
vim ~/.bash_profile
export PATH=$PATH:ChromeDriver目录(注意,是存放的目录,不是这个文件)
:wq
source ~/.bash_profile
-
driver = webdriver.Chrome()
成功
3.
参考官网代码,把chrome driver目录作为参数path传给web driver
-
path = "/---/---path---/--/chromedriver"
-
driver = webdriver.Chrome(path)
此处一定要给出chromedriver的全目录,成功
阅读(13111) | 评论(0) | 转发(0) |