Dot-Net

Internet Explorer 保護模式錯誤

  • October 9, 2014

我在 Visual Studio 中的程式碼使用的是 selenium webdriver 2.24.0。我正在使用的測試框架是 Nunit。在 2.24.0 版本發布之前,我的程式碼執行良好(載入不同的瀏覽器、驅動網站)。

我將新的 IE 獨立伺服器添加到我的項目中。

現在,每當我執行我的程式碼時,NUnit 都會遇到此錯誤消息。

FirstSeleniumTest.SeleniumTest.TestGoogle:
SetUp : System.InvalidOperationException : Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for all zones. (NoSuchDriver)
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.

然後命令提示符彈出這個。

Started InternetExplorerDriver server (64-bit)
2.24.0.0
Listening on port 50329

我在我的 IE 上禁用了保護模式。仍然沒有運氣。

我怎樣才能讓我的程式碼恢復到正確的網路驅動?

您應確保為所有4 個安全區域(Int​​ernet、本地 Intranet、受信任站點、受限制站點)啟用或禁用保護模式。換言之,所有安全區域的設置值應該相同。

只是為了添加到已經正確的答案,如果將所有值設置為相同不是一個選項,(需要禁用安全性是某些區域,但希望在其他區域保持啟用安全性)您還可以使用包含的重載初始化驅動程序InternetExplorerOptions,並且採用

new InternetExplorerOptions() { IntroduceInstabilityByIgnoringProtectedModeSettings = true}

引用自:https://stackoverflow.com/questions/11121773