Java ChromeDriver - 禁用 Selenium WebDriver 自动化上弹出的开发者模式扩展

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23087724/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 20:37:13  来源:igfitidea点击:

ChromeDriver - Disable developer mode extensions pop up on Selenium WebDriver automation

javaseleniumselenium-webdriverselenium-chromedriver

提问by elcharrua

I'm having the following issue: When I'm running my automation tests, I keep getting the following alert "Disable Developer Mode Extension" in Chrome.

我遇到了以下问题:当我运行自动化测试时,我在 Chrome 中不断收到以下警报“禁用开发人员模式扩展”。

enter image description here

在此处输入图片说明

Is there a way to remove/disable this?. It is a blocker for me as it is making me fail some tests.

有没有办法删除/禁用它?这对我来说是一个障碍,因为它使我无法通过一些测试。

Thanks in advance

提前致谢

采纳答案by Mauricio

Did you try disabling the developer extensions with command line param?

您是否尝试使用命令行参数禁用开发人员扩展?

Try with the following Selenium WebDriver java code:

尝试使用以下 Selenium WebDriver java 代码:

System.setProperty("webdriver.chrome.driver", "D:\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-extensions");
driver = new ChromeDriver(options);

回答by Mike B

This is because one of your extensions is running in developer mode. Go through your extension list and disable extensions one-by-one until you find the culprit(s).

这是因为您的一个扩展程序正在开发人员模式下运行。浏览您的扩展列表并逐一禁用扩展,直到找到罪魁祸首。

回答by Richard

I worked around this issue by using AutoIT.

我通过使用 AutoIT 解决了这个问题。

First, you'll need to create the script.

首先,您需要创建脚本。

closechromewarning.au3:

closechromewarning.au3:

WinWaitActive("[CLASS:Chrome_WidgetWin_1]")
Send("{ESC}")

The script needs to be compiled to a .exe, then place the .exein the path so it can be run.

脚本需要编译为.exe,然后将.exe放在路径中以便它可以运行。

Function that closes the warning, using c# syntax:

关闭警告的函数,使用 c# 语法:

public void CloseChromeDialog()
{
    System.Threading.Thread.Sleep(5000);
    Process.Start(@".\closechromewarning.exe");
}

Sleep(4000)did work, but I upped it to Sleep(5000)just to be sure.

Sleep(4000)确实有效,但我将其提高到Sleep(5000)只是为了确定。

Calling CloseChromeDialog():

呼叫CloseChromeDialog()

if(browser == chrome) //pseudo code
    CloseChromeDialog();

回答by Erik Eidt

I cannot disable extensions because I'm developing & testing one.

我无法禁用扩展,因为我正在开发和测试一个。

What I'm doing to dismiss this popup is the following:

我要关闭此弹出窗口的操作如下:

  1. I load chrome with my extension using Selenium.
  2. I then immediately create a new window (via the SendKeys(Control-N)method). This predictably brings up the "Disable Developer Mode Extensions" popup after 3 seconds in the new window.
  3. I can't tell programmatically when it pops up (doesn't show in screenshots) so instead I simply wait 4 seconds.
  4. Then I close the tab via driver.Close();(which also closes this new window). Chrome takes that as "cancel", dismissing the popup, leaving the original window and tab.
  1. 我使用 Selenium 将 chrome 与我的扩展程序一起加载。
  2. 然后我立即创建一个新窗口(通过SendKeys(Control-N)方法)。可以预见,这会在 3 秒后在新窗口中弹出“禁用开发人员模式扩展”弹出窗口。
  3. 我无法以编程方式判断它何时弹出(未显示在屏幕截图中),因此我只是等待 4 秒钟。
  4. 然后我关闭选项卡通过driver.Close();(这也关闭了这个新窗口)。Chrome 将其视为“取消”,关闭弹出窗口,保留原始窗口和选项卡。

I find this necessary because the popup interferes with normal selenium browser interaction, like SendKeys, which I'm using to switch tabs and windows.

我认为这是必要的,因为弹出窗口会干扰正常的 selenium 浏览器交互,比如我用来切换选项卡和窗口的 SendKeys。

回答by sateesh

I too faced this problem. The solution is, if you are using maven then just add:

我也遇到了这个问题。解决方案是,如果您使用的是 maven,那么只需添加:

-Dchrome.switches=--disable-extensions

-Dchrome.switches=--disable-extensions

It will disable all the extensions and you will not face this problem.

它将禁用所有扩展程序,您将不会遇到此问题。

回答by RArora

This has been automatically fixed with a combination of ChromeDriver.exe V2.23+ Chrome 53.0.

这已通过ChromeDriver.exe V2.23+ Chrome 53.0的组合自动修复。

To understand which chrome version will work with which driver, we can use the following well detailed doc: https://sites.google.com/a/chromium.org/chromedriver/downloads

要了解哪个 chrome 版本适用于哪个驱动程序,我们可以使用以下详细的文档:https: //sites.google.com/a/chromium.org/chromedriver/downloads

Enjoy Automated Testing!!

享受自动化测试!!

回答by CRISTIANO BARBOSA

resolved in chrome 54 and chromedriver 2.25

在 chrome 54 和 chromedriver 2.25 中解决

回答by Sudhanva Patil

I am using selenium Webdriver 2.53 and chrome version 56.0.2924.87 and the chrome driver.exe which I am using is 2.27. with this combination it is working with the

我使用 selenium Webdriver 2.53 和 chrome 版本 56.0.2924.87,我使用的 chrome driver.exe 是 2.27。通过这种组合,它正在与

System.setProperty("webdriver.chrome.driver", "./utilities/chromedriver.exe");          
ChromeOptions options = new ChromeOptions();        
options.addArguments("--disable-extensions");           
DesiredCapabilities caps = new DesiredCapabilities().chrome();
caps.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(caps);

回答by Jess

Try to add setProperty above ChromeDriver instance

尝试在 ChromeDriver 实例上方添加 setProperty

System.setProperty("webdriver.chrome.driver","C:/[PATH]/chromedriver.exe");
driver = new ChromeDriver(capabilities);

回答by Peter P

As of Chromedriver v2.33, the correct way to avoid this message is to pass load-extensionto the excludeSwitchesargument of the chromeOptionsobject. The following Java code should do the trick, although I haven't tested it, as I am running Python:

从 Chromedriver v2.33 开始,避免此消息的正确方法是传递load-extension给对象的excludeSwitches参数chromeOptions。下面的 Java 代码应该可以解决这个问题,虽然我没有测试过它,因为我正在运行 Python:

ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("excludeSwitches", Collections.singletonList("load-extension"));

As others have pointed out, the culprit is probably the Chrome Automation Extension, which is loaded automatically by Chromedriver when it launches Chrome.

正如其他人指出的那样,罪魁祸首可能是 Chrome 自动化扩展,它在启动 Chrome 时由 Chromedriver 自动加载。

Chromedriver v2.33 introducedthe new switch to prevent the extensions from being loaded:

Chromedriver v2.33引入了新的开关来阻止加载扩展:

Updates to excludeSwitches capability that now allows to exclude --load-extension switch.

更新 excludeSwitches 功能,现在允许排除 --load-extension 开关。

I suspect that this solution does not require you to disable all extensions. You should still be able to manually load others.

我怀疑此解决方案不需要您禁用所有扩展。您应该仍然可以手动加载其他人。