Bob*_*byB 18 java selenium google-chrome selenium-chromedriver serenity-bdd
我正在使用Serenity BDD(Selenium)在Chrome中运行自动化测试.
我不得不下载新的ChromeDriver,因为我的测试无法运行 - >测试会打开ChromeDriver,但无法"以用户身份浏览".当我搜索问题时,他们说我必须更新ChromeDriver.
所以我将ChromeDriver更新到版本2.28,我还将Chrome版本更新为版本57.0.2987.98.
但现在 - 每次我运行测试时都会出现这个烦人的文字:
Chrome由自动化测试软件控制
它问我是否要保存密码.(我无法添加图片,因为我没有足够的"积分")
在之前的版本中,我设法通过以下方式阻止这两件事:
public class CustomChromeDriver implements DriverSource {
@Override
public WebDriver newDriver() {
try {
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
Proxy proxy = new Proxy();
String proxyServer = String.format("AProxyIDontWantToDisplay", System.getenv("proxy.username"), System.getenv("proxy.password"));
proxy.setHttpProxy(proxyServer);
capabilities.setCapability("proxy", proxy);
ChromeOptions options = new ChromeOptions();
options.addArguments(Arrays.asList("--no-sandbox","--ignore-certificate-errors","--homepage=about:blank","--no-first-run"));
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);
return driver;
} catch (Exception e) {
throw new Error(e);
}
}
@Override
public boolean takesScreenshots() {
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
我知道有这个(相同问题的链接),但有太多的答案不起作用.
有谁知道如何删除它?
jgo*_*ode 29
将其添加到传递给驱动程序的选项中:
options.addArguments("disable-infobars");
Run Code Online (Sandbox Code Playgroud)
小智 7
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("useAutomationExtension", false);
options.setExperimentalOption("excludeSwitches",Collections.singletonList("enable-automation"));
WebDriver driver = new ChromeDriver(options);
Run Code Online (Sandbox Code Playgroud)
将上述代码用于最新的 Chrome 驱动程序。
关于"Chrome由自动测试软件控制"文本弹出:它不会影响您的测试.要处理其他事情(例如:保存密码),您可以在代码中添加以下行.
ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_settings.popups", 0);
options.addArguments("disable-extensions");
prefs.put("credentials_enable_service", false);
prefs.put("password_manager_enabled", false);
options.setExperimentalOption("prefs", prefs);
options.addArguments("chrome.switches","--disable-extensions");
options.addArguments("--test-type");
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(ChromeOptions.CAPABILITY, options);
cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
System.setProperty("webdriver.chrome.driver",*path of chromedriver.exe*);
wb = new ChromeDriver(cap);
Run Code Online (Sandbox Code Playgroud)
希望它能奏效.
最新的 chromedriver 不再支持“禁用信息”开关。(至少 76.0)。
@Rajeev 的答案有效,在这里我为 C# 编写了对应的答案。
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddAdditionalCapability("useAutomationExtension", false);
chromeOptions.AddExcludedArgument("enable-automation");
Driver = new ChromeDriver(chromeOptions);
Run Code Online (Sandbox Code Playgroud)
小智 6
工作时间 2022 年
删除Chrome被python中的自动化测试软件控制
from selenium.webdriver.chrome.webdriver import WebDriver
from selenium.webdriver.chrome.options import Options
chromeOptions = webdriver.ChromeOptions()
chromeOptions.add_experimental_option("excludeSwitches", ['enable-automation']);
URL = "https://google.com/"
driver.get(URL)
Run Code Online (Sandbox Code Playgroud)
小智 5
尝试了许多建议的解决方案,但没有一个起作用。好的,我的代码是用 C# 编写的,因此不同平台的 WebDriver 实现可能会存在一些差异。
不管怎样,我得到的解决方案是在 .NET 上运行时使用 Chrome 的以下选项。
var options = new ChromeOptions();
options.AddExcludedArguments("enable-automation");
Run Code Online (Sandbox Code Playgroud)
在 .NET 上,该类似乎没有任何setExperimentalOption()方法ChromeOptions。
| 归档时间: |
|
| 查看次数: |
31623 次 |
| 最近记录: |