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

Var*_*ati 4 c# selenium google-chrome selenium-chromedriver chrome-automation-extension

我使用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.
Run Code Online (Sandbox Code Playgroud)

点击弹出窗口的确定按钮后,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
Run Code Online (Sandbox Code Playgroud)

每次硒打开镀铬时,它都会将自动化扩展加载到镀铬中以与之配合使用.

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

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

我尝试使用AddExtension和类的AddArgument方法ChromeOptions,但没有一个工作,并得到相同的错误.

有人可以帮助我克服这个问题吗?

小智 10

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

我做了这样的事情(JAVA):

ChromeOptions o = new ChromeOptions();
o.addArguments("disable-extensions");
o.addArguments("--start-maximized");
WebDriver driver = new ChromeDriver(o);
Run Code Online (Sandbox Code Playgroud)

第二行就是你所需要的.第三行只是使镀铬窗口最大化.

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