【问题标题】:Selenium with Chromedriver can't allow Chrome to know Location带有 Chromedriver 的 Selenium 不能让 Chrome 知道位置
【发布时间】:2023-01-13 03:56:57
【问题描述】:

当出现询问我是否允许的弹出窗口时,我不能让 Chrome 知道位置。

我将 nuget Selenium 4.3.0 与 .Net 6 和 chromedriver 版本 103.0.5060.66 一起使用

我尝试了很多在互联网上找到的解决方案(Stackoverflow、medium、github Issue list 等),但没有任何效果,我不知道是我做错了什么还是新版本中有一些错误硒(我试图降级到 4.0.0 仍然是问题)

我使用以下 Chrome 选项:

  chromiumOptions.AddArgument("--disable-infobars");
  chromiumOptions.AddArgument("--ignore-certificate-errors");
  chromiumOptions.AddArgument("--allow-running-insecure-content");
  chromiumOptions.AddArgument("--disable-blink-features=AutomationControlled");
  chromiumOptions.AddArgument("--disable-dev-shm-usage");
  chromiumOptions.AddArguments("headless");
  chromiumOptions.AddAdditionalChromeOption("useAutomationExtension", false);
  chromiumOptions.AddExcludedArgument("enable-automation");
  chromiumOptions.AddArguments("--disable-gpu");
  chromiumOptions.AddArgument("--no-sandbox");

我尝试了以下选项但没有结果:(也尝试使用 AddAdditionalCapability 和 AddAdditionalOption)

chromiumOptions.AddUserProfilePreference("profile.default_content_settings.geolocation", 1);
chromiumOptions.AddUserProfilePreference("profile.managed_default_content_settings.geolocation", 1);

我也尝试使用 cdp 命令

Dictionary<string, object> commandParameters = new Dictionary<string, object>();
commandParameters = new Dictionary<string, object>();
commandParameters.Add("origin", "https://www.openstreetmap.org");
commandParameters.Add("permissions", new List<string>() { "geolocation" });
seleniumBrowser.ExecuteCdpCommand("Browser.grantPermissions", commandParameters);

但是没有任何效果,仍然出现 Chrome 位置弹出窗口询问我是否要允许。

提前致谢!

【问题讨论】:

    标签: selenium selenium-chromedriver geolocation


    【解决方案1】:

    我刚刚遇到了同样的问题,我在这里创建了一个错误报告:

    https://github.com/SeleniumHQ/selenium/issues/11542

    -- 目前,我的工作是创建一个不自动接受地理位置的测试版本。我希望它已修复(如果它是一个错误)

    【讨论】:

      猜你喜欢
      • 2018-06-05
      • 1970-01-01
      • 2013-09-09
      • 2020-07-24
      • 2017-01-16
      • 2019-07-31
      • 1970-01-01
      • 2011-04-07
      • 1970-01-01
      相关资源
      最近更新 更多