2017-07-31 131 views
0

我想要做的第一件事就是在Windows中安裝Selenium。Selenium Webdriver安裝錯誤

所以安裝硒與pip install selenium,並試圖與

from selenium import webdriver 

導入,但我得到了

Traceback (most recent call last): File "C:\Users\admin\AppData\Local\Programs\Python\Python36-32\selentest.py", line 1, in from selenium import webdriver ModuleNotFoundError: No module named 'selenium'

所以我做了我的錯誤的VM中的VirtualBox(卡利的Linux,Debian的64)和嘗試在那裏安裝Selenium。

它工作得很好,但後來我得到了webdriver的問題。

我選擇火狐Geckodriver(在https://github.com/mozilla/geckodriver/releases geckodriver-v0.18.0-linux32.tar.gz)

我輕拍到名爲 「硒」(/根/桌面/硒)的文件夾,並放置在以下腳本到它:

from selenium import webdriver 
from selenium.webdriver.common.keys import Keys 
driver = webdriver.Firefox("/root/Desktop/Selenium/") 
driver.get("http://www.python.org") 

,並得到了錯誤:

[email protected]:~/Desktop/Selenium# python main.py 
Traceback (most recent call last): 
    File "main.py", line 4, in <module> 
    driver = webdriver.Firefox("/root/Desktop/Selenium/") 
    File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 152, in __init__ 
    keep_alive=True) 
    File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 98, in __init__ 
    self.start_session(desired_capabilities, browser_profile) 
    File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 188, in start_session 
    response = self.execute(Command.NEW_SESSION, parameters) 
    File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 256, in execute 
    self.error_handler.check_response(response) 
    File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response 
    raise exception_class(message, screen, stacktrace) 
selenium.common.exceptions.WebDriverException: Message: Unable to find a matching set of capabilities 

這裏也是webdriver的的屬性的截圖: http://imgur.com/a/xdKHw

+1

它看起來像你在混合python版本,在Windows上它看起來像你使用的是3.6,而在你正在使用的linux上2。7,它看起來像你試圖在Linux上使用Windows WebDriver(這將不起作用) –

+0

它可能有幾個版本的Python安裝在Windows上,並且你已經安裝了硒的不同版本正在嘗試使用。 –

+0

它現在全部聚集在一起:DDD – user8393645

回答

0

確定,所以得到這個工作,你需要幾件事情:

  1. 蟒蛇的版本你打算使用(並不重要,只要你知道的版本
  2. 的安裝目錄硒Python模塊
  3. 合適的webdriver二進制

所以假設你已經有1項,我們需要得到第2項
在窗口上:

cd c:\python36\scripts 
pip install selenium 

其中36意味着python 3.6,所以替換爲您使用的版本。

在Linux上的python2.x:

pip install selenium 

在Linux上的python3.x:

pip3 install selenium 

,最後得到我們需要下載該操作系統相匹配的webdriver的第三個項目。
從這裏 這樣:https://github.com/mozilla/geckodriver/releases
在Windows上,我們需要無論是Win32發佈(32位Windows)或Win64的版本(64和Windows)

,並在Linux上,我們需要linux32鏡像版本(32位Linux)或linux64發佈(64位linux)

+0

hm,我找不到python36的路徑,但是我安裝了python 3.6(python3 -v說3.6) – user8393645

+0

http://imgur.com/a/V9xfE這樣做絕對沒有意義 – user8393645

+0

確定修復了1000感謝 – user8393645