2016-07-06 29 views
11

我正在嘗試使用python-selenium API(版本2.53.6)在不同的瀏覽器上執行GUI測試。當我嘗試按以下方式使用IE(11.0.10240)時(Windows Server 2012 R2 Standard,64位);使用認證:如何使用從硒的IE瀏覽器的python的webdriver(導航錯誤失敗)?

driver = webdriver.Ie() 
driver.get("http://user:[email protected]") 

然後我收到以下錯誤信息:

selenium.common.exceptions.WebDriverException: Message: Failed to navigate to http://user:[email protected] This usually means that a call to the COM method IWebBrowser2::Navigate2() failed. 

有沒有辦法解決這個問題?

附錄:

  • 我一直在嘗試使用IE瀏覽器的驅動程序的32位版本,沒有成功(同樣的錯誤)
  • 我已經改變了註冊表解釋here,沒有成功(同樣的錯誤)
  • 我已經爲所有區域設置了「啓用保護模式」(也建議here)。
+0

如果您嘗試導航到某個其他網站,它是否工作?它可能與使用http ...有關。另外,當你說你已經設置「啓用保護模式」,你的意思是你禁用它,對嗎?另外,嘗試使用Internet選項>高級下的安全部分 –

回答

1

沒有直接回答這個問題,但使用IE11時通過BrowserStack開放this http auth protected page我無法重現它在Windows 10:

from selenium import webdriver 

desired_cap = {'os': 'Windows', 'os_version': '10', 'browser': 'IE', 'browser_version': '11.0'} 

driver = webdriver.Remote(
    command_executor='http://usename:[email protected]:80/wd/hub', 
    desired_capabilities=desired_cap) 

driver.get("http://httpwatch:[email protected]/httpgallery/authentication/authenticatedimage/default.aspx?0.7349707232788205") 

沒有錯誤,我看到的是HTTP認證背後的圖像。

使用硒2.53.5。

+0

下的設置進行播放。如果我嘗試這樣做,會在'webdriver.Remote'行中出現404錯誤。我還非常喜歡獲得我的示例代碼中給出的驅動程序,即具有返回正確且正常工作的驅動程序的方法(不需要事先指定特定的URL ...)。 – Alex

+0

@Alex這裏的自定義'command_executor'網址只是因爲我在Mac上並使用遠程瀏覽器selenium服務器並在那裏啓動了'IE'。然後,我導航到特定的'httpwatch'頁面,以證明我可以訪問基本http認證背後的圖像。請注意,如果你想運行這個例子,你需要用你的特定瀏覽器證書替換'username'和'key'。 – alecxe

+0

我不想使用browserstack ...也許硒只是不工作的IE瀏覽器的目的? – Alex

0

你試過用這種方法嗎?

driver.current_url(" http://user:[email protected] ")

+0

似乎'current_url'是我無法調用的字符串。我得到一個錯誤'TypeError:'str'object is not callable' ... – Alex

+0

你介意分享一些更多的細節嗎?像 >你使用的是什麼版本的Python? >您在程序中調用哪個頭文件導入? >如果可能,基本上發佈你的整個代碼? – Technologeek