如何自动接受Chrome浏览器的“始终在关联的应用中打开这些类型的链接", Selenium中的对话框 [英] How to automatically accept Chrome's "Always open these types of links in the associated app" dialogs in Selenium

查看:1970
本文介绍了如何自动接受Chrome浏览器的“始终在关联的应用中打开这些类型的链接", Selenium中的对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Selenium和C#自动化测试,我需要从浏览器中打开一个外部应用程序.问题是,我总是收到此通知,它阻止了测试的执行.

I'm automating tests using Selenium and C# and I need to open an external app from the browser. The problem is, I always get this notification and it blocks the test execution.

有人知道如何处理吗?

推荐答案

Chrome浏览器将接受协议处理程序的设置存储在用户个人资料中.从Selenium运行Chrome时,默认情况下,Chrome似乎没有使用标准的Chrome用户配置文件,而是使用了一些未保留的默认设置.

Chrome stores the settings for the acceptance of protocol handlers in the user profile. When running Chrome from Selenium, Chrome doesn't seem to use the standard Chrome user profile by default, and instead uses some default settings that are not persisted.

要解决此问题,您可以从命令行手动启动Chrome,然后手动指定新的--user-data-dir=c:\foo\bar配置文件位置. (将其指向一个新的/空目录,Chrome会为您填充它.)

To get around this, you can launch Chrome from the command line manually and manually specify a new --user-data-dir=c:\foo\bar profile location. (Point it to a new/empty directory and Chrome will populate it for you.)

使用此手动启动的浏览器,导航到需要与之交互的页面,激活链接,单击始终打开"复选框,然后运行该程序一次.

Using this manually-launched browser, navigate to the page you need to interact with, activate the link, click the "always open" checkbox, and run the program once.

接下来,关闭Chrome,然后保存整个新用户个人资料目录的副本.在运行Selenium测试时,请确保始终将相同的命令行选项传递给Chrome,使其指向该用户个人资料.这些设置现已保留,因此该链接将在以后无需用户干预的情况下打开. (此问题可能有助于向Chrome提供正确的命令行参数.)

Next, close Chrome and save a copy of the entire new user profile directory. When you run your Selenium tests, make sure to always pass Chrome the same command line options pointing it to that user profile. These settings are now persisted, so the link will open without user intervention in the future. (This question may be of help to feed the right command line args to Chrome.)

对于可重复的测试,您可能希望保存此配置文件的静态副本,并在每次启动Selenium时重新部署它.

For repeatable tests, you will probably want to save a static copy of this profile and redeploy it whenever you launch Selenium.

这篇关于如何自动接受Chrome浏览器的“始终在关联的应用中打开这些类型的链接", Selenium中的对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆