简体   繁体   English

具有BinaryLocation的C#Google Chrome Selenium URL导航

[英]C# Google Chrome Selenium URL Navigation with BinaryLocation

Greetings StackOverflow Community, 问候StackOverflow社区,

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. 我有以下五行代码,无法弄清楚为什么使用自定义二进制位置时Google Chrome浏览器不会启动google.com

        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. 我所得到的是启动Chrome浏览器时默认的chromedriver URL“ data: ”。

Why isn't the driver.navigate command working when using a Chrome.BinaryLocation? 使用Chrome.BinaryLocation时为什么driver.navigate命令不起作用? If I comment out that line, than it works fine. 如果我注释掉那条线,那会很好。

I am using the following: 我正在使用以下内容:

  • Windows 7 Windows 7的
  • Visual Studio Community Edition 2017 Visual Studio社区版2017
  • Google Chrome version 67 Google Chrome版本67
  • chromedriver 2.41 chromedriver 2.41
  • .NET 4.5 Bindings .NET 4.5绑定

hey i dont think you need of binary location 嘿,我不认为您需要二进制位置

And maybe Chrome is already a type, 也许Chrome已经是一种类型,

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. 我不知道为什么Firefox,Chrome或其他基于Chromium的浏览器的可移植版本无法通过这种方式运行,但是我通过将企业安装文件从Chrome的程序文件复制到计算机上的另一个目录,然后指向Selenium脚本以使用该二进制位置。 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. 将Chrome指向自定义Chrome配置文件位置也很有用,以防止更多的Chrome应用程序使用本地用户的AppData文件夹。

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. 只是给我发消息以获取更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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