Recent versions of Chrome display notification bar at the top of the browser saying "Chrome is being controlled by automated test software", as follows:
Previously, passing the "disable-infobars” ChromeOption to the WebDriver prevented Chrome from displaying this notification. Recently, the "disable-infobars" option has been deprecated and no longer removes the notification. The current workaround for this is to pass in an option called "excludeSwitches" and then exclude the "enable_automation" switch.
CAUTION: Please review what the "enable_automation" switch does via the documentation and ensure your test suite does not rely on any features listed there before disabling it.
Here is the relevant syntax to do so:
When using ChromeDriver
Java:
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("excludeSwitches", new String[]{"enable-automation"});
WebDriver driver = new ChromeDriver(options);
Protractor:
exports.config = {
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
'excludeSwitches': ['enable-automation']
}
},
specs: ['ProtractorExample.js']
};
JavaScript:
var chromeCapabilities=webdriver.Capabilities .chrome()
var chromeOptions = {
'excludeSwitches': ['enable-automation']
};
chromeCapabilities.set('chromeOptions' , chromeOptions);
var driver = new webdriver.Builder()
.withCapabilities(chromeCapabilities)
.build();
Python:
chrome_options = webdriver.ChromeOptions();
chrome_options.add_experimental_option("excludeSwitches", ['enable-automation']);
driver = webdriver.Chrome(options=chrome_options);
Ruby:
options = Selenium::WebDriver::Chrome::Options.new(options: {"excludeSwitches" => ["enable-automation"]})
driver = Selenium::WebDriver.for :chrome, options: options
Java:
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("excludeSwitches", new String[]{"enable-automation"});
DesiredCapabilities caps = DesiredCapabilities.chrome();
caps.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new RemoteWebDriver(caps);
Protractor:
exports.config = {
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
'excludeSwitches': ['enable-automation']
}
},
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['ProtractorExample.js']
};
JavaScript:
var chromeCapabilities=webdriver.Capabilities .chrome()
var chromeOptions = {
'excludeSwitchest': ['enable-automation']
};
chromeCapabilities.set('chromeOptions' , chromeOptions);
var driver = new webdriver.Builder().forBrowser('chrome').usingServer('http://localhost:4444/wd/hub' ).withCapabilities (chromeCapabilities).build();
Python:
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["enable-automation"])
caps = options.to_capabilities()
driver = webdriver.Remote(command_executor ='http://127.0.0.1:4444/wd/hub' ,
desired_capabilities=caps)
Ruby:
caps = Selenium::WebDriver::Remote::Capabilities.chrome("chromeOptions" => {"excludeSwitches" => [ "enable-automation" ]})
driver = Selenium::WebDriver.for :remote, url: 'http://localhost:4444/wd/hub', desired_capabilities: caps