4

我似乎無法通過Selenium 2的Python庫打開Goog​​le Chrome或Internet Explorer。我正在使用Windows 7,64位。IE和Chrome不能使用Selenium2 Python

我已經完成以下步驟:

  • 安裝了Python - 2.7.5
  • 安裝硒2.33
  • 包括C:\ Python27 & C:\ Python27 \ Scripts中的環境變量 - 路徑
  • 下載32位(我正在運行64位,但我找不到32位版本)Windows Chrome驅動程序支持v27-30(我在28),並將其放入C:\ Python27 \ Scripts
  • 下載支持IE9的64位IE驅動程序(我將IE10降級爲IE9)。我把司機到C:\ Python27 \ Scripts中

每當我鍵入:

from selenium import webdriver 
driver = webdriver.Ie() 

OR

from selenium import webdriver 
driver = webdriver.Chrome() 

到Python外殼,沒有瀏覽器彈出,外殼只是凍結幾分鐘後輸出錯誤信息。

IE錯誤消息:

selenium.common.exceptions.WebDriverException: Message: 'Can not connect to the IEDriver' 

Chrome的錯誤消息:

urllib2.HTTPError: HTTP Error 503: Service Unavailable 

它完美精緻與Firefox。有趣的是,這個進程(IEDriver和ChromeDriver)是通過TaskManager啓動的,但是窗口從不顯示。

+0

謝謝。我只是嘗試將它放入自己的文件夾並更新PATH,但仍然沒有幫助。 –

回答

7

在蟒硒webdriver.Ie只是用於執行IEDriver.exe並通過webdriver.Remote連接到它的快捷方式。例如,你可以在命令行啓動IEDriver.exe

> IEDriverServer.exe 
Started InternetExplorerDriver server (64-bit) 
2.39.0.0 
Listening on port 5555 

,並與下面的代碼替換webdriver.Ie()

webdriver.Remote(command_executor='http://127.0.0.1:5555', 
       desired_capabilities=DesiredCapabilities.INTERNETEXPLORER)` 

你會得到相同的結果。

特別是在你的情況下,最有可能的是你有一些系統代理設置,強制它通過代理服務器連接到127.0.0.1。可能當您按照回答Python: Disable http_proxy in urllib2中所述禁用它時,您可以解決問題:

import selenium 
import urllib2 
from contextlib import contextmanager 

@contextmanager 
def no_proxies(): 
    orig_getproxies = urllib2.getproxies 
    urllib2.getproxies = lambda: {} 
    yield 
    urllib2.getproxies = orig_getproxies 

with no_proxies(): 
    driver = selenium.webdriver.Ie() 
    driver.get("http://google.com") 
+0

是的,檢查你的環境變量HTTP_PROXY和HTTPS_PROXY –

1

我一直沒能解決這個問題,我已經將它下載到路徑,但已經能夠通過定義的驅動程序的路徑要解決它,就像這樣:

driver = webdriver.Chrome('C:\path\to\chromedriver') 

driver = webdriver.Ie('C:\path\to\iedriver') 
+0

我剛剛嘗試過,但它仍然不適用於我:/ –

+0

爲了讓事情變得更加令人困惑,這隻適用於Chrome。即使仍然給我一個錯誤信息...我很困惑 – KjetilNordin

相關問題