1.下載32位的python3.4 ,安裝,註意在安裝過程中,選擇pip
2.添加系統環境變量
C:\Python34;C:\Python34\Scripts;C:\Program Files\Google\Chrome\Application(後面會用到)
3.使用pip命令,安裝selenium
cd Python34
然後輸入: pip install -U selenium
安裝成功後,顯示:
Runing setup.py install foe selenium
Successfully installed selenium-2.48.0
4.檢測selenium是否安裝成功。
在Python的IDLE中,輸入:
from selenium import webdriver
如果沒有報錯,則selenium安裝成功。
5.開始第壹個程序
from selenium import webdriver
driver = webdriver.Chrome()
driver.get(““)
driver.find_element_by_id(“kw”).send_keys(“自動化測試”)
按F5運行,然後會自動打開百度網頁。
能夠順利安裝,那是幸運的,但是更多時候,總因為各種原因導致安裝過程不太順利。
下面將安裝過程中遇到的問題,總結在此:
issue 1:
使用pip 命令安裝結束後,加載selenium模塊報錯。
from selenium import webdriver
報錯:
File “pyshell#0”, line 1, in
import selenium
File “C:\Python34\selenium.py”, line 1, in
from selenium import webdriver
ImportError: cannot import name ‘webdriver’
Traceback (most recent call last):
File “pyshell#0”, line 1, in
import selenium
File “C:\Python34\selenium.py”, line 1, in
from selenium import webdriver
百度了很多方法,仍無解。
解決方法: 最後換了版本,將64位python3.4 改為32位的python3.4
再次重新安裝,成功。
issue 2:
使用browser=webdriver.Chorme() 報錯。
報錯:
Error message: “’chromedriver’ executable needs to be available in the path”
這是因為缺少驅動:Chromedriver.exe
下載Chormedriver.exe
註意安裝Chromedriver.exe要與PC所安裝的Chrome版本匹配。
解決方法:下載安裝ChromeDrvier.exe 將ChromeDrvier.exe 放到C:\Python34\Scripts\