4

I am automating my application using Selenium Webdriver, C#, Visual Studio and Chrome browser.

I am getting below popup when selenium tried to open the chrome browser.

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.

Once I click on OK button of the popup, Chrome is opening successfully but my test is failing due to below error.

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

Every time selenium open chrome it will load automation extension into chrome to work with it.

But in our organization we are using google mail and our IT department blocked adding extensions(third party and unpacked) to Chrome browser for security reasons.

If I modified the registry to allow third party extensions, test is executing successfully. But our IT department updates the policy every day on every system(automated).

I tried using AddExtension and AddArgument methods of ChromeOptions class, but none of them worked and got the same error.

Can someone help me to overcome this issue?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

7 Answers7

9

I tried using AddExtension and AddArgument methods of ChromeOptions class, but none of them worked and got the same error.

I did something like this (JAVA):

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

The second line is all what you need. The third line is just making chrome window maximized.

The pop-up isn't showing up currently. HTH.

ksokol
  • 8,035
  • 3
  • 43
  • 56
jakbeb
  • 91
  • 1
  • 4
  • wow. this actually seems to work. i wonder if there is some capability that is lost/broken without the extension but my test is running now – Robert Levy Jun 21 '16 at 20:19
4

Hope this below solution will help you.

  1. Open Registry Editor
  2. Search for below keys HKEY_CURRENT_USER\Software\Policies\Google\Chrome\ExtensionInstallBlacklist HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome\ExtensionInstallBlacklist
  3. If you find any keys set under above location, just delete it.
prathyush
  • 51
  • 2
3

Help overcome how, exactly?

Selenium requires a helper extension to function. An enterprise policy lockdown is in effect, so you can't add it.

You will need to raise the problem with your IT dept if you want to run tests, after all you have a valid reason.

Update: It seems that Selenium can now run without the automation extension. See, for example, this answer for details on how to start Chrome without the extension if you must avoid its use.


Chromedriver seems to always put its unpacked extension into a random temp location, which causes a random ID. This makes it impossible to whitelist the extension.

In fact, no, the ID of the extension is pinned. However, the enterprise policy does not allow whitelisting of unpacked extensions. Which is reasonable, as it would allow to bypass the security (all you need is the key fields in the manifest to impersonate the ID).

Making Chromedriver load packed extensions seems to require a lot of reworking, and considering the Windows limitations on installing them may be downright impossible.

Corresponding Chromedriver bug (very much ignored, it seems).

Xan
  • 74,770
  • 16
  • 179
  • 206
2

The part of the stack trace

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

is because of 3rd party extensions installed on Chrome. Check if you have any extensions installed, like Add Blockers or something.

I encountered the same problem and was able to solve them by deleting the extensions installed in Chrome. If you have any extensions installed in chrome I am pretty sure removing them should solve the issue.

SohailAQ
  • 1,002
  • 1
  • 13
  • 25
  • Selenium, unless you do some very specific things, always starts with an empty profile. – Xan Apr 15 '15 at 06:39
  • @Xan I guess you are confused about third party extensions and Selenium WebDriver. Can you please state reason for occurrence of the same extension in the error as the ID of Chrome extension? In my case the ID in the stack trace was same as the ID of one of the installed extensions, how do you answer that? – SohailAQ Apr 15 '15 at 11:08
  • Selenium Chromedriver works by creating an unpacked copy of all extensions it was asked to inject, always including its own "helper" extension with the above ID. Then it loads Chrome with a new, blank profile (so no extensions unless you specifically override the user data folder with Chromedriver options) and tries to add extensions as unpacked. Chrome, regardless of profile, **reads enterprise policy and blocks loading the helper extension** (as evidenced by Chrome output). Chromedriver then fails to find the extension with the stack trace above. – Xan Apr 15 '15 at 11:15
  • Disclaimer: I've never used Selenium Chromedriver, but specifically for this question I took a look at its source code and bug tracker to confirm. – Xan Apr 15 '15 at 11:16
  • You are talking about the extensions Selenium has control on, I am talking about extensions you have manually installed to Chrome (3rd Party extensions). I am confident on this because of matching ID's of the 3rd Party extensions and the extension ID present in the stack trace. How can that be wrong? – SohailAQ Apr 15 '15 at 11:27
  • This is specifically the ID of the Chromedriver helper extension, or "Chrome Automation Extension", not a 3rd-party extension. You can confirm by a Google search for the ID, or [this line of code](https://code.google.com/p/chromium/codesearch#chromium/src/chrome/test/chromedriver/chrome/chrome_desktop_impl.cc&l=144). – Xan Apr 15 '15 at 11:33
  • Also, this whole situation is a [known bug](https://code.google.com/p/chromedriver/issues/detail?id=639) that I mentioned in my answer. – Xan Apr 15 '15 at 11:41
  • Okay. I guess you are right then. I was seeing the problem from what I have encountered and hurried on answering the question. [This](http://stackoverflow.com/questions/29506731/google-chrome-unable-to-navigate-to-specified-url-when-triggered-from-selenium/29642673#29642673) was the problem I was facing and was able to solve it the specified way. Anyways thanks for the link. – SohailAQ Apr 15 '15 at 11:45
1

According to ChromeDriver Issues use the following:

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

Extra: For using Selenium with 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)
})
YourAboutMeIsBlank
  • 1,787
  • 3
  • 18
  • 27
0

The unpacked extension error popped up for me and I requested for removing the restrictions in chrome which was enforced as organizational policy. Once the restrictions were removed, I am able to run the program with out any errors. ChromeBrowser-GPO-Deny - this was the one which was removed. You can check in Settings - Extensions - Check on Developer mode and see if the load unpacked extensions is checked once the restrictions are removed. You should be good then.

Syam
  • 11
  • 2
  • We are currently experiencing this unpacked extension issue in our Protractor E2E testing. I have found this post which discusses a new option , `chromeOptions.useAutomationExtensions` - https://bugs.chromium.org/p/chromium/issues/detail?id=604324 (see Comment 22 on Mar 31 post). Has anyone successfully implemented this option ? If I can't implement this option properly then we will have to communicate to our IT department what Chrome extension needs to be approved/whitelisted. The problem again is that the helper extension appears to be unpacked into a different folder each time... – bob.mazzo Aug 08 '17 at 16:43
  • I did not do that as my issue was resolved when browser deny was removed. Good luck with that and please let us know as well. – Syam Aug 11 '17 at 18:24
0

This error message...

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.

As per the discussion Failed to load extention from: ... Loading of unpacked extensions is disabled by the administrator ChromeDriver uses Chrome automation extension for automating various functions like window sizing, window positioning, etc.

The Failed to load extension popup means that this extension has not been loaded. If you manually close the popup, browser will act normally and ChromeDriver commands will continue to work as expected. But in this case if you try executing window resizing or window re-positioning commands, it will throw an error as unknown error: cannot get automation extension.

Background: Till ChromeDriver v2.28 whenever an organizations admin policy forbidden extensions, to bypass the restriction users have used the argument disable-extensions as follows (Java Code Sample):

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

and it worked perfecto.

ChromeDriver v2.28 onwards, whenever disable-extensions flag is passed by test, ChromeDriver implicitly passes disable-extensions-except flag which in turn loads Chrome automation extension. This extension helps Chromedriver to perform window sizing and window re-positioning operations.

So, if your organizational admin policy blocks extensions, display of popup Failed to load extension from: ... Loading of unpacked extensions is an expected behavior.

Solution

As a solution, you can set the useAutomationExtension capability to false as follows (Java Code Sample):

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

This capability inturn will help to not load Chrome Automation extension and Failed to load extension popup would not appear. But you will not be able to perform any window resizing/positioning operations without the Chrome automation extension.

trivia

The best approach would be to use the latest version of ChromeDriver and Chrome combination among either of the following:

  • If you are using Chrome version 73, please download ChromeDriver 73.0.3683.20
  • If you are using Chrome version 72, please download ChromeDriver 2.46 or ChromeDriver 72.0.3626.69
  • If you are using Chrome version 71, please download ChromeDriver 2.46 or ChromeDriver 71.0.3578.137
  • For older version of Chrome, please see this discussion.

Alternatives

Some diverse alternatives:

  • Add the Registry Key ExtensionInstallWhitelist to whitelist
  • Remove the Registry Key ExtensionInstallBlacklist containing a string key 1 with value *
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352