无法使用Selenium Webdriver打开Chrome浏览器。 管理员禁用加载解压缩的扩展名

我使用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开铬时,它都会将自动化扩展加载到铬中以便与之配合使用。

但在我们的组织中,我们使用谷歌邮件,我们的IT部门出于安全原因阻止向Chrome浏览器添加扩展程序(第三方和解压缩)。

如果我修改了注册表以允许第三方扩展,则测试正在成功执行。 但是我们的IT部门每天都在每个系统上更新策略(自动化)。

我尝试使用ChromeOptions类的AddExtensionAddArgument方法,但它们都没有工作并得到相同的错误。

有人可以帮我解决这个问题吗?

我尝试使用ChromeOptions类的AddExtension和AddArgument方法,但它们都没有工作并得到相同的错误。

我做了这样的事( JAVA ):

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

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

弹出窗口目前没有显示。 HTH。

希望以下解决方案能为您提供帮助。

  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是固定的。 但是,企业策略不允许将解压缩的扩展名列入白名单。 这是合理的,因为它允许绕过安全性(您需要的只是清单中用于模拟ID的key段)。

制作Chromedriver加载扩展似乎需要大量的重做,并且考虑到Windows安装它们的限制可能是完全不可能的。

相应的Chromedriver bug (非常被忽略,似乎)。

根据ChromeDriver问题,请使用以下内容:

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

额外:使用Selenium和Cucumber-js

 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) }) 

堆栈跟踪的一部分

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

是因为Chrome上安装了第三方扩展程序。 检查您是否安装了任何扩展程序,例如Add Blockers等。

我遇到了同样的问题,并且能够通过删除Chrome中安装的扩展程序来解决这些问题。 如果您在chrome中安装了任何扩展程序,我很确定删除它们可以解决问题。

为我弹出了解压缩的扩展错误,并且我要求删除chrome中作为组织策略强制执行的限制。 删除限制后,我可以运行程序而不会出现任何错误。 ChromeBrowser-GPO-Deny – 这是删除的那个。 您可以签入设置 – 扩展 – 检查开发人员模式,并查看一旦删除限制,是否检查了加载解压扩展。 那你应该好。