我在mac和ubunto上运行自动化(使用黄瓜,硒网络驱动程序,junit)
在自动化过程中,我点击了一个非http协议的链接
出现“外部协议请求”弹出窗口。
它阻止我的测试测试网页的其余部分。
如何轻松绕过它?
我原本以为可能会编写一个什么也不做的jar然后将它注册到这个外部协议,但是这个弹出窗口仍然会出现,所以它无济于事。
也许使用其他浏览器可以提供帮助吗?
还有其他建议吗?
答案 0 :(得分:3)
我正在使用含有硒和蟒蛇的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://"开头的链接禁止协议处理程序弹出窗口
只需在"sip":True
"protocol_handler.excluded_schemes"
条目即可
答案 1 :(得分:1)
您有两种可能的选择。
1)运行带有预定义配置文件的chrome,您已手动禁用协议处理(通过接口或配置文件)("本地状态"配置文件设置中的文件,您应该添加" waze":在相应部分中为false,您可以搜索" mailto"以了解它的位置。
2)另一种方法是将设置放入测试中。所有测试开始之前的构造函数(我会写一个算法,因为它取决于你的框架和语言):
答案 2 :(得分:0)
使用AutoIT(Windows环境的第三方工具)。 *)安装它(无论是64位还是32位OS) *)使用Finder工具(AutoIT v3窗口信息),识别"什么都不做"
示例:位置(700,430)
*)在AutoIT ScriptEditor中添加以下代码MouseClick(" left"," 700,430)并将其另存为.au3文件格式。
*)在您的脚本中添加此代码Runtime.getRuntime()。exec(" D:\ AutoIt \ AutoItTest.exe");
*)运行你的脚本。
答案 3 :(得分:0)
对于那些正在寻找Javascript-Selenium或webdriverJS答案的人,这里是您可以做到的。
chromeOptions = {
'args': ['--test-type',
'--start-maximized',
'use-fake-ui-for-media-stream',],
'prefs': {
protocol_handler: {
excluded_schemes: {
'iamlegend': false
}
}
},
};
用协议替换“ iamlegend”
答案 4 :(得分:0)
对于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);