簡體   English   中英

無法使用 Selenium Webdriver 打開 Chrome 瀏覽器。 加載解壓的擴展被管理員禁用

[英]Unable to open chrome browser using Selenium Webdriver. Loading unpacked extensions are disabled by administrator

我正在使用 Selenium Webdriver、C#、Visual Studio 和 Chrome 瀏覽器自動化我的應用程序。

當 selenium 嘗試打開 chrome 瀏覽器時,我正在彈出窗口下方。

Failed to load extension from:C:\Users\VARA~1.PAK\AppData\Local\Temp\scoped_dir6712_14913\internal.
Loading of unpacked extensions is disabled by the administrator.

單擊彈出窗口的“確定”按鈕后,Chrome 將成功打開,但由於以下錯誤,我的測試失敗。

Test Name:  _3_EnterDetailsAndSelectAnAddress_John
Test FullName:  Veolia.BrentGWP.UserStories.Features.BrentGWPFeature._3_EnterDetailsAndSelectAnAddress_John
Test Source:     : line 2147483647
Test Outcome:   Failed
Test Duration:  0:00:47.8059413

Result Message: 
Test method Veolia.BrentGWP.UserStories.Features.BrentGWPFeature._3_EnterDetailsAndSelectAnAddress_John threw exception: 
System.InvalidOperationException: unknown error: cannot get automation extension
from unknown error: page could not be found: chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/_generated_background_page.html
  (Session info: chrome=41.0.2272.118)
  (Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86_64)
Assert.Fail failed. Please check through the execution report against scenario
Result StackTrace:  
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebDriver.InternalExecute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWindow.Maximize()
   at Veolia.Libraries.Driver.BeforeScenario() in c:\development\Veolia.Web.Brent\development\testing\Automation\Veolia.test.Framework\Libraries\Driver.cs:line 105
   at lambda_method(Closure , IContextManager )
   at TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration)
   at TechTalk.SpecFlow.Bindings.BindingInvokerExtensions.InvokeHook(IBindingInvoker invoker, IHookBinding hookBinding, IContextManager contextManager, ITestTracer testTracer)
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.FireEvents(HookType bindingEvent)
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.FireScenarioEvents(HookType bindingEvent)
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnScenarioStart(ScenarioInfo scenarioInfo)
   at TechTalk.SpecFlow.TestRunner.OnScenarioStart(ScenarioInfo scenarioInfo)
   at Veolia.BrentGWP.UserStories.Features.BrentGWPFeature.ScenarioSetup(ScenarioInfo scenarioInfo) in c:\development\Veolia.Web.Brent\development\testing\Automation\Veolia.test.Framework\BrentGWP\UserStories\Features\AddressSearch.feature.cs:line 0
   at Veolia.BrentGWP.UserStories.Features.BrentGWPFeature._3_EnterDetailsAndSelectAnAddress(String firstname, String lastname, String postcode, String email, String phoneNumber, String[] exampleTags) in c:\development\Veolia.Web.Brent\development\testing\Automation\Veolia.test.Framework\BrentGWP\UserStories\Features\AddressSearch.feature:line 16
   at Veolia.BrentGWP.UserStories.Features.BrentGWPFeature._3_EnterDetailsAndSelectAnAddress_John() in c:\development\Veolia.Web.Brent\development\testing\Automation\Veolia.test.Framework\BrentGWP\UserStories\Features\AddressSearch.feature.cs:line 0

每次 selenium 打開 chrome 時,它​​都會將自動化擴展加載到 chrome 中以使用它。

但在我們的組織中,我們使用谷歌郵件,出於安全原因,我們的 IT 部門阻止向 Chrome 瀏覽器添加擴展程序(第三方和解包)。

如果我修改了注冊表以允許第三方擴展,則測試成功執行。 但是我們的 IT 部門每天都會在每個系統上更新策略(自動化)。

我嘗試使用ChromeOptions類的AddExtensionAddArgument方法,但它們都ChromeOptions並出現相同的錯誤。

有人可以幫我解決這個問題嗎?

我嘗試使用 ChromeOptions 類的 AddExtension 和 AddArgument 方法,但它們都不起作用並出現相同的錯誤。

我做了這樣的事情( JAVA ):

ChromeOptions o = new ChromeOptions();
o.addArguments("disable-extensions");
o.addArguments("--start-maximized");
WebDriver driver = new ChromeDriver(o);

第二行就是你所需要的。 第三行只是使鍍鉻窗口最大化。

彈出窗口當前未顯示。 哈。

希望以下解決方案對您有所幫助。

  1. 打開注冊表編輯器
  2. 搜索以下鍵 HKEY_CURRENT_USER\\Software\\Policies\\Google\\Chrome\\ExtensionInstallBlacklist HKEY_LOCAL_MACHINE\\SOFTWARE\\Policies\\Google\\Chrome\\ExtensionInstallBlacklist
  3. 如果您發現在上述位置下設置了任何鍵,只需將其刪除。

幫助克服如何,究竟?

Selenium 需要一個輔助擴展才能運行。 企業策略鎖定已生效,因此您無法添加它。

如果您想運行測試,您需要向 IT 部門提出問題,畢竟您有正當理由。

更新: Selenium 現在似乎可以在沒有自動化擴展的情況下運行。 例如,如果您必須避免使用擴展程序,請參閱此答案以了解有關如何在沒有擴展程序的情況下啟動 Chrome 的詳細信息。


Chromedriver 似乎總是將其解壓縮的擴展程序放到一個隨機的臨時位置, 這會導致隨機 ID。 這使得無法將擴展列入白名單。

事實上,不,擴展的ID是固定的。 但是,企業策略不允許將解壓縮的擴展程序列入白名單。 這是合理的,因為它可以繞過安全性(您只需要清單中的key段來模擬 ID)。

使 Chromedriver 加載打包的擴展程序似乎需要大量返工,考慮到 Windows 對安裝它們的限制可能是完全不可能的。

相應的Chromedriver 錯誤(似乎被忽略了很多)。

堆棧跟蹤的部分

  System.InvalidOperationException: unknown error: cannot get automation extension from unknown error: page could not be found: chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/_generated_background_page.html

是因為 Chrome 上安裝了 3rd 方擴展程序。 檢查您是否安裝了任何擴展程序,例如添加阻止程序或其他東西。

我遇到了同樣的問題,並且能夠通過刪除 Chrome 中安裝的擴展來解決它們。 如果您在 chrome 中安裝了任何擴展,我很確定刪除它們應該可以解決問題。

根據ChromeDriver 問題使用以下內容:

chromeOptions: {
    args: ['--start-maximized', '--disable-extensions'],
    useAutomationExtension: false
}

額外:用於在 Cucumber-js 中使用 Selenium

require('chromedriver')
var seleniumWebdriver = require('selenium-webdriver');
var {defineSupportCode} = require('cucumber');

function CustomWorld() {

  var chromeCapabilities = seleniumWebdriver.Capabilities.chrome();

  var chromeOptions = {
    'args': ['--disable-extensions', '--start-maximized'],
    'useAutomationExtension': false
  };

  chromeCapabilities.set('chromeOptions', chromeOptions);

  this.driver = new seleniumWebdriver.Builder()
    .forBrowser('chrome')
    .withCapabilities(chromeCapabilities)
    .build();
}

defineSupportCode(function({setWorldConstructor}) {
  setWorldConstructor(CustomWorld)
})

為我彈出了解壓擴展錯誤,我要求刪除 chrome 中作為組織政策強制執行的限制。 取消限制后,我就可以運行程序而不會出現任何錯誤。 ChromeBrowser-GPO-Deny - 這是被刪除的那個。 您可以在設置 - 擴展 - 檢查開發人員模式中檢查,看看一旦取消限制,是否檢查加載解壓擴展。 那你應該很好。

這個錯誤信息...

Failed to load extension from:C:\Users\VARA~1.PAK\AppData\Local\Temp\scoped_dir6712_14913\internal.
Loading of unpacked extensions is disabled by the administrator.

...implies that an extension was not been loaded as it was disabled by the administrator.

根據討論Failed to load extension from: ... 管理員禁止加載未打包的擴展ChromeDriver使用Chrome 自動化擴展來自動化各種功能,如窗口大小調整、窗口定位等。

Failed to load extension彈出窗口意味着此擴展程序尚未加載。 如果您手動關閉彈出窗口,瀏覽器將正常運行, ChromeDriver命令將繼續按預期工作。 但是在這種情況下,如果您嘗試執行窗口大小調整或窗口重新定位命令,則會拋出一個錯誤為unknown error: cannot get automation extension

背景:直到ChromeDriver v2.28每當組織管理策略禁止擴展時,為了繞過限制,用戶使用參數disable-extensions如下( Java 代碼示例):

ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-extensions");
WebDriver driver = new ChromeDriver(options);

它完美地工作。

從 ChromeDriver v2.28開始,每當測試通過disable-extensions標志時, ChromeDriver 會隱式傳遞disable-extensions-except標志,該標志又會加載Chrome 自動化擴展 此擴展程序幫助 Chromedriver 執行窗口大小調整和窗口重新定位操作。

因此,如果您的組織管理策略阻止擴展,則顯示彈出窗口無法從以下位置加載擴展:...加載解壓縮的擴展是預期行為。

解決方案

作為解決方案,您可以將useAutomationExtension功能設置為false ,如下所示( Java 代碼示例):

ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("useAutomationExtension", false);
WebDriver driver = new ChromeDriver(options);

此功能反過來將有助於不加載Chrome 自動化擴展程序,並且不會出現Failed to load extension彈出窗口。 但是如果沒有Chrome 自動化擴展,您將無法執行任何窗口大小調整/定位操作。

瑣事

最好的方法是使用最新版本的ChromeDriverChrome組合,其中之一是:

  • 如果您使用的是Chrome 73 版本,請下載ChromeDriver 73.0.3683.20
  • 如果您使用的是Chrome 72 版,請下載ChromeDriver 2.46ChromeDriver 72.0.3626.69
  • 如果您使用的是Chrome 71 版,請下載ChromeDriver 2.46ChromeDriver 71.0.3578.137
  • 對於舊版本的 Chrome,請參閱此討論

備擇方案

一些不同的選擇:

  • 注冊表項ExtensionInstallWhitelist添加到白名單
  • 刪除包含值為*的字符串鍵1注冊表項ExtensionInstallBlacklist

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM