简体   繁体   中英

C# Google Chrome Selenium URL Navigation with BinaryLocation

Greetings StackOverflow Community,

My issue is simple. I have the following five lines of code, that I can't figure out why Google Chrome doesn't launch google.com when using a custom binary location.

        var Chrome = new ChromeOptions();
        Chrome.AddArgument("no-sandbox");
        Chrome.BinaryLocation = @"C:\GoogleChrome\chrome.exe";
        ChromeDriver driver = new ChromeDriver(@"C:\ChromeDriver", Chrome);
        driver.Navigate().GoToUrl("https://www.google.com");

Any ideas? All I get is the default chromedriver URL of " data:, " when Google Chrome launches.

Why isn't the driver.navigate command working when using a Chrome.BinaryLocation? If I comment out that line, than it works fine.

I am using the following:

  • Windows 7
  • Visual Studio Community Edition 2017
  • Google Chrome version 67
  • chromedriver 2.41
  • .NET 4.5 Bindings

hey i dont think you need of binary location

And maybe Chrome is already a type,

try this:

ChromeOptions options = new ChromeOptions();
options.AddArgument("no-sandbox");
var driver = new ChromeDriver(@"C:\GoogleChrome", options);
driver.Navigate().GoToUrl("https://www.google.com");

Okay, I found the answer to this question. I don't know why the Portable version of either Firefox, Chrome or other Chromium based browsers do not function this way, but I resolved this issue by copying the enterprise installation files from program files for Chrome to another directory on the computer and then pointing the Selenium script to use that binary location. Then it worked just fine.

It was also useful to point Chrome to a custom chrome profile location to keep more of the Chrome application from using the local users's AppData folder.

If anyone is interested in accomplishing the same task, I can provide some example code that accomplishes this task. Just message me for more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM