title: How to avoid Access Denied when using selenium browser automation
body: <p>I will try to describe the problem with a sample code. Here is a code in C# that opens an instance of a Chrome browser and navigates to nseindia.com:</p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading;
  using System.Threading.Tasks;
  using OpenQA.Selenium;
  using OpenQA.Selenium.Chrome;
  using OpenQA.Selenium.Support.UI;
  
  namespace nseindia_selenium
  {
      class Program
      {
          static void Main( string [ ] args )
          {
              ChromeOptions options = new ChromeOptions ();
              options.BinaryLocation = &quot;C:\\Users\\Subhasis\\AppData\\Local\\Chromium\\Application\\chrome.exe&quot;;
              //options.AddAdditionalCapability ( &quot;w3c&quot; , true );
              options.AddArgument ( &quot;no-sandbox&quot; );
              options.AddArgument ( &quot;start-maximized&quot; );
              options.AddArgument ( &quot;disable-gpu&quot;);
              options.AddArgument ( &quot;user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36&quot; );
              options.AddExcludedArgument ( &quot;enable-automation&quot; );
              options.AddAdditionalCapability ( &quot;useAutomationExtension&quot; , false );
              //options.AddAdditionalCapability ( &quot;chrome.page.customHeaders.referrer&quot; , &quot;https://www.nseindia.com&quot; );
              ChromeDriver chrome1 = new ChromeDriver (options);
              chrome1.Navigate ().GoToUrl ( &quot;https://www.nseindia.com/&quot; );
          }
      }
  }
  </code></pre>
  <p>Things seem to be working this far (not really, all data fields appear empty). But at this stage,if I take manual control of the browser window and try to browse to any other part of nseindia.com, I get an error:
  <a href="https://i.stack.imgur.com/qNQ9Y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qNQ9Y.png" alt="enter image description here" /></a></p>
  <p>At this point, even if I try to go back to the homepage of the website, it does not let me do it.</p>
  <p>Past answers of this same question recommended manually setting the referrer. But when I do,</p>
  <pre><code>options.AddAdditionalCapability ( &quot;chrome.page.customHeaders.referrer&quot; , &quot;https://www.nseindia.com&quot; );
  </code></pre>
  <p>it is giving me &quot;Invalid argument&quot; error. Also, if it is a fault of referrer, that does not explain why manualy clicking a link does not work.</p>
  <p>The past answers had also recommended using</p>
  <pre><code>options.AddAdditionalCapability ( &quot;useAutomationExtension&quot; , false );
  </code></pre>
  <p>But that does not work anymore because I get this message:</p>
  <pre><code>[1601022727.512][WARNING]: Deprecated chrome option is ignored: useAutomationExtension
  [1601022727.512][WARNING]: Deprecated chrome option is ignored: useAutomationExtension
  </code></pre>
  <p>In the past this used to happen because of wrong w3c mode, but I can not switch w3c mode anymore either. when I put</p>
  <pre><code>options.AddAdditionalCapability ( &quot;w3c&quot; , true );
  </code></pre>
  <p>I get an error saying:</p>
  <pre><code>System.ArgumentException: 'There is already an option for the w3c capability. Please use the  instead.
  Parameter name: capabilityName'
  </code></pre>
  <p>So what do I do?</p>