【问题标题】:Bypass "External protocol request" popup during selenium automation在硒自动化期间绕过“外部协议请求”弹出窗口
【发布时间】:2015-06-15 18:24:44
【问题描述】:

我在 mac 和 ubunto 上运行自动化(使用 cucumber、selenium web driver、junit)

在自动化过程中,我单击非 http 协议的链接

出现“外部协议请求”弹出窗口。

它阻止我的测试测试网页的其余部分。

如何轻松绕过?

我想也许可以写一个什么都不做的 jar,然后将它注册到这个外部协议,但这无济于事,因为这个弹出窗口仍然会出现。

也许使用其他浏览器会有所帮助?

还有其他建议吗?

【问题讨论】:

标签: java testing selenium selenium-webdriver webdriver


【解决方案1】:

我正在使用带有 selenium 和 python 的 chromedriver。 我遇到了同样的问题,下面的代码对我有用-

driver.execute_script("window.confirm = function(msg) { return true; }")

prefs = {"protocol_handler.excluded_schemes":{"afp":True,"data":True,"disk":True,"disks":True,"file":True,"hcp":True,"intent":True, "itms-appss":True, "itms-apps":True,"itms":True,"market":True,"javascript":True,"mailto":True,"ms-help":True,"news":True,"nntp":True,"shell":True,"sip":True,"snews":False,"vbscript":True,"view-source":True,"vnd":{"ms":{"radio":True}}}}    

chrome_options.add_experimental_option("prefs",prefs)

假设您想禁止以“sip://”开头的链接的协议处理程序弹出窗口
只需在"protocol_handler.excluded_schemes" 中添加一个额外的条目为"sip":True

【讨论】:

  • 更好的答案
  • 在C#驱动中你必须使用Options.AddUserProfilePreference("protocol_handler.excluded_schemes", new Dictionary<string,bool>{{"ms-excel", false}});
【解决方案2】:

您有 2 个可能的选择。

1) 正在运行具有预定义配置文件的 chrome,您已手动禁用协议处理(通过接口或配置文件)(配置文件设置中的“本地状态”文件,您应该在相应部分添加“位智”:false ,你可以搜索“mailto”知道它在哪里)。

2) 另一种方法是在所有测试开始之前将设置放入测试的构造函数中(我将编写一个算法,因为它取决于您的框架和语言):

  • 导航到“chrome://settings”
  • 使用 CSS 选择器“#advanced-settings-expander”按下链接
  • 按下带有 css 选择器“#privacyContentSettingsButton”的按钮
  • 使用 css 选择器“#handlers-section input[value=block]”按所需选项的标签
  • 通过 CSS 选择器“#content-settings-overlay-confirm”按下完成

【讨论】:

  • 1) a) 如何远程 webdriver 使用特定的 chrome 设置或配置文件? 1)b)它也适用于mac吗? 2)如果我只是切换到FF,它会在不改变设置的情况下工作吗?
  • 1) a - 通过 ChromeOptions,效果如何 - 取决于您的框架。在 java ChromeOptions 选项 = new ChromeOptions(); options.addArguments("user-data-dir="+userProfile); WebDriver driver = new ChromeDriver(options); 1) b-确定。 2)对于 ff 它应该是另一种选择
  • 有没有办法将它抑制到所有配置文件?这意味着默认情况下没有应用程序将处理此协议,除非特定配置文件明确配置?
  • 据我所知 - 没有。
  • 我添加了:"waze":false,"mailto":false,,但弹出窗口出现了。网络驱动程序打开一个匿名 chrome 配置文件
【解决方案3】:

对于 Firefox,以下 C# 代码添加了一个协议处理程序:

firefoxOptions.SetPreference("network.protocol-handler.external.your_custom_protocol", true);
firefoxOptions.SetPreference("network.protocol-handler.expose.your_custom_protocol", true);
firefoxOptions.SetPreference("network.protocol-handler.warn-external.your_custom_protocol", false);

Internet Explorer 将协议处理程序存储在注册表中(仅适用于本地 WebDriver):

var baseKey = @"Software\Microsoft\Internet Explorer\ProtocolExecute\your_custom_protocol";
var protocolKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(baseKey, true) ?? Microsoft.Win32.Registry.CurrentUser.CreateSubKey(baseKey);

protocolKey?.SetValue("WarnOnOpen", 0, Microsoft.Win32.RegistryValueKind.DWord);

【讨论】:

    【解决方案4】:

    通过使用 AutoIT(Windows 环境的第三方工具)。 *)安装它(无论是 64 位还是 32 位操作系统) *) 使用 Finder 工具(AutoIT v3 Window info),确定“什么都不做”的位置

    示例:位置 (700,430)

    *)在 AutoIT ScriptEditor 中添加以下代码 MouseClick("left","700,430) 并将其保存为 .au3 文件格式。

    *)在你的脚本中添加这段代码 Runtime.getRuntime().exec("D:\AutoIt\AutoItTest.exe");

    *)运行你的脚本。

    【讨论】:

    • 首先这需要编辑。其次,很明显提问者不在 windows 环境中。
    【解决方案5】:

    对于那些正在寻找 Javascript-selenium 或 webdriverJS 答案的人来说,这里是你可以做到的。 chromeOptions = { 'args': ['--test-type', '--start-maximized', 'use-fake-ui-for-media-stream',], 'prefs': { protocol_handler: { excluded_schemes: { 'iamlegend': false } } }, };

    用您的协议替换“iamlegend”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-19
      • 2021-03-24
      • 2021-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-27
      • 2018-06-22
      相关资源
      最近更新 更多