Selenium c# Multiple Options

0

I'm trying to use multiple options on my selenium project with Chrome as driver, but when i try to add headless + extension i got an error

System.InvalidOperationException occurred HResult=0x80131509
Message=unknown error: failed to wait for extension background page to load: chrome-extension://jmphljmgnagblkombahigniilhnbadca/_generated_background_page.html from unknown error: page could not be found: chrome-extension://jmphljmgnagblkombahigniilhnbadca/_generated_background_page.html (Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 10.0.15063 x86_64) Source=WebDriver 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.StartSession(ICapabilities desiredCapabilities) at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities) at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeOptions options) at SeleniumTest.Form1.<>c__DisplayClass5_0.b__0() in C:\Users\Ussagui\source\repos\SeleniumTest\SeleniumTest\Form1.cs:line 53 at System.Threading.Tasks.Task.InnerInvoke() at System.Threading.Tasks.Task.Execute()

my code is:

var option = new ChromeOptions();

            option.AddArguments("--headless --disable-gpu");
            option.AddExtensions(@"EXTENSION PATH");

            var driver = new ChromeDriver(option);
            var action = new Actions(driver);

            driver.Navigate().GoToUrl(URL);

if i use only the extension or argument it works. How can i use both? Or i cant? Thank in advance.

c#
google-chrome
selenium
webdriver
asked on Stack Overflow Oct 26, 2017 by Ussagui

1 Answer

0

A few points:

  1. Though the arguments --headless and --disable-gpu are interrelated but are used for separate tasks. Hence we need to specify them separately.

  2. Use optimal code block and comment/remove the debug/unused code. As driver.Navigate().GoToUrl(URL); doesn't need WebDriver instance to be casted so we need to comment/remove var action = new Actions(driver);

  3. Your final code block will look like:

    var option = new ChromeOptions();
    option.AddArguments("--headless");
    option.AddArguments("--disable-gpu");
    option.AddExtensions(@"EXTENSION PATH");
    var driver = new ChromeDriver(option);
    driver.Navigate().GoToUrl(URL);
    
answered on Stack Overflow Oct 27, 2017 by DebanjanB

User contributions licensed under CC BY-SA 3.0