I am curious to know the capabilities of the Chrome browser opened through the code:
driver=webdriver.chromedriver()
Is it same as that of incognito mode or is there a different kind?
To extract the capabilities of the ChromeDriver / Chrome Browser you can use the capabilities property which returns a dictionary and you can use the following solution:
Code Block:
from selenium import webdriver
driver = webdriver.Chrome(executable_path="C:\\Utility\\BrowserDrivers\\chromedriver.exe")
my_dict = driver.capabilities
for key,val in my_dict.items():
print (key, "=>", val)
driver.quit()
Console Output:
acceptInsecureCerts => False
browserName => chrome
browserVersion => 76.0.3809.100
chrome => {'chromedriverVersion': '76.0.3809.68 (420c9498db8ce8fcd190a954d51297672c1515d5-refs/branch-heads/3809#{#864})', 'userDataDir': 'C:\\Users\\Debanjan.B\\AppData\\Local\\Temp\\scoped_dir3888_683123771'}
goog:chromeOptions => {'debuggerAddress': 'localhost:26050'}
networkConnectionEnabled => False
pageLoadStrategy => normal
platformName => windows nt
proxy => {}
setWindowRect => True
strictFileInteractability => False
timeouts => {'implicit': 0, 'pageLoad': 300000, 'script': 30000}
unhandledPromptBehavior => dismiss and notify
You can find a relevant discussion in How to provide custom capabilities on the selenium server?
Related
The warning I'm receiving is: WARN Selenium [DEPRECATION] [:capabilities_hash] passing a Hash value to :capabilities is deprecated. Use Capabilities instance initialized with the Hash, or build values with Options class instead.
My driver setup looks like:
Capybara.register_driver :aws_chrome do |app|
client = Selenium::WebDriver::Remote::Http::Default.new
client.read_timeout = 180
capabilities = {
'browserName': 'chrome',
'aws:maxDurationSecs': 2400
}
Capybara::Selenium::Driver.new(app, browser: :remote, http_client: client, url: remote_url, capabilities: capabilities)
end
I'm not sure what a capabilities instance is supposed to be, and there's no documentation on how to use the Options class that I could find. I also need to be able to set the browserName to firefox as needed, so I'm not sure if the Options class is specific to chrome.
Thanks in advance.
I'm not familiar with ruby, but for using options instead of capabilities try:
Capybara.register_driver :aws_chrome do |app|
client = Selenium::WebDriver::Remote::Http::Default.new
client.read_timeout = 180
options = Selenium::WebDriver::Chrome::Options.new
options.add_option('aws:maxDurationSecs', 2400)
Capybara::Selenium::Driver.new(app, browser: :remote, http_client: client, url: remote_url, options: options)
end
This is Options class api doc for selenium 4:
https://www.selenium.dev/selenium/docs/api/rb/Selenium/WebDriver/Options.html
With version 75 of Chrome just released, our tests no longer run properly. They give the stacktrace pasted below. We are using ruby on rails v. 5.1.6.2 with rspec, selenium-webdriver 3.8.0.
Stacktrace:
Selenium::WebDriver::Error::UnknownCommandError:
unknown command: Cannot call non W3C standard command while in W3C mode
# 0 chromedriver 0x000000010c46e8e9 chromedriver + 3594473
# 1 chromedriver 0x000000010c3fe543 chromedriver + 3134787
# 2 chromedriver 0x000000010c1aa29f chromedriver + 692895
# 3 chromedriver 0x000000010c11a691 chromedriver + 104081
# 4 chromedriver 0x000000010c11b7d5 chromedriver + 108501
# 5 chromedriver 0x000000010c42d555 chromedriver + 3327317
# 6 chromedriver 0x000000010c438e60 chromedriver + 3374688
# 7 chromedriver 0x000000010c438bf8 chromedriver + 3374072
# 8 chromedriver 0x000000010c40cd39 chromedriver + 3194169
# 9 chromedriver 0x000000010c4396d8 chromedriver + 3376856
# 10 chromedriver 0x000000010c420f27 chromedriver + 3276583
# 11 chromedriver 0x000000010c456064 chromedriver + 3493988
# 12 chromedriver 0x000000010c474617 chromedriver + 3618327
# 13 libsystem_pthread.dylib 0x00007fff7744c2eb _pthread_body + 126
# 14 libsystem_pthread.dylib 0x00007fff7744f249 _pthread_start + 66
# 15 libsystem_pthread.dylib 0x00007fff7744b40d thread_start + 13
# /Users/julie/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.8.0/lib/selenium/webdriver/remote/response.rb:69:in `assert_ok'
# /Users/julie/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.8.0/lib/selenium/webdriver/remote/response.rb:32:in `initialize'
# /Users/julie/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.8.0/lib/selenium/webdriver/remote/http/common.rb:81:in `new'
# /Users/julie/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.8.0/lib/selenium/webdriver/remote/http/common.rb:81:in `create_response'
# /Users/julie/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.8.0/lib/selenium/webdriver/remote/http/default.rb:104:in `request'
# /Users/julie/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.8.0/lib/selenium/webdriver/remote/http/common.rb:59:in `call'
# /Users/julie/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.8.0/lib/selenium/webdriver/remote/bridge.rb:166:in `execute'
# /Users/julie/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.8.0/lib/selenium/webdriver/remote/oss/bridge.rb:579:in `execute'
# /Users/julie/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.8.0/lib/selenium/webdriver/remote/oss/bridge.rb:526:in `element_displayed?'
# /Users/julie/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.8.0/lib/selenium/webdriver/common/element.rb:199:in `displayed?'
# /Users/julie/.rvm/gems/ruby-2.5.1/gems/capybara-2.17.0/lib/capybara/selenium/node.rb:148:in `visible?'
# /Users/julie/.rvm/gems/ruby-2.5.1/gems/capybara-2.17.0/lib/capybara/node/element.rb:269:in `block in visible?'
# /Users/julie/.rvm/gems/ruby-2.5.1/gems/capybara-2.17.0/lib/capybara/node/base.rb:81:in `synchronize'
# /Users/julie/.rvm/gems/ruby-2.5.1/gems/capybara-2.17.0/lib/capybara/node/element.rb:269:in `visible?'
# /Users/julie/.rvm/gems/ruby-2.5.1/gems/capybara-2.17.0/lib/capybara/queries/selector_query.rb:84:in `matches_filters?'
# /Users/julie/.rvm/gems/ruby-2.5.1/gems/capybara-2.17.0/lib/capybara/result.rb:29:in `block in initialize'
Our driver configuration:
File.write(LOG_FILE_PATH, '')
Selenium::WebDriver.logger.level = :debug
Selenium::WebDriver.logger.output = LOG_FILE_PATH
Capybara.register_driver :selenium do |app|
# from https://github.com/SeleniumHQ/selenium/issues/3738
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(loggingPrefs: {browser: 'ALL'})
options = Selenium::WebDriver::Chrome::Options.new
options.add_argument '--disable-infobars' # hide info bar about chrome automating test
# if we don't use this flag, every selenium test will die with the error:
# "unknown error: Chrome failed to start: exited abnormally"
options.add_argument '--no-sandbox'
options.add_argument '--headless' if ENV.fetch("HEADLESS", nil).present?
options.add_argument '--window-size=1600,2400'
options.add_argument '-–allow-file-access-from-files' # TODO Julie - may help with file specs?
options.add_preference('homepage', 'about:blank') # TODO is this working?
options.add_preference('profile.default_content_settings.popups', 0)
options.add_preference('download.default_directory', DownloadHelpers::PATH.to_s)
Capybara::Selenium::Driver.new(
app,
clear_local_storage: true,
clear_session_storage: true,
browser: :chrome,
options: options,
desired_capabilities: capabilities,
)
end
UPDATE:
I was able to get our tests to work temporarily using capabilities = { "chromeOptions" => {'w3c' => false} }.
After updating chromedriver, we began receiving the error "unknown error: DevToolsActivePort file doesn't exist". In order to fix this problem, we upgraded our selenium-webdriver gem to 3.142.3 and this fixed the issue, allowing us to use w3c without any additional parameters.
First the solution
As promised by John Chen [Owner - WebDriver for Google Chrome] yesterday, new versions of ChromeDriver 75.0.3770.90 and 76.0.3809.25 have been released, and are now available at the ChromeDriver Downloads site. These versions include the following bug fixes over the previous releases of ChromeDriver 75 and 76:
Fixed a bug that incorrectly rejected POST requests with empty body in OSS mode
Added new endpoints for retrieving Chrome log
In addition, version 76.0.3809.25 also includes the following change:
Added endpoint for Is Displayed command in W3C mode
Email Snapshot
Details
It will be against the best practices to turn off w3c in chromedriver to address the error:
Selenium::WebDriver::Error::UnknownCommandError:
unknown command: Cannot call non W3C standard command while in W3C mode
as the current implementation of ChromeDriver requests a W3C-compliant session to the client.
However, this error message implies that the ChromeDriver was unable to invoke a non W3C standard command while in W3C mode while initiating/spawning a new WebBrowser i.e. Chrome Browser session.
The main issue is, when ChromeDriver's client requests a W3C-compliant session, the response from ChromeDriver does not conform to the W3C spec, and causes errors in language APIs.
As per the discussion in ChromeDriver response in W3C mode is not standard compliant John Chen (Owner - WebDriver for Google Chrome) mentioned Simon Stewart (Creator - WebDriver) have updated that:
The new session response for a w3c session should look like:
{
"value": {
"sessionId": "some-uuid",
"capabilities": {
"browserName": "chrome",
...
}
}
}
But when starting a new session with the w3c option set to true in the chromeOptions, the returned response looked like:
{
"sessionId": "af4656c27fb94485b7872e1fc616923a",
"status": "ok",
"value": {
"browserName": "chrome",
...
}
}
Which is neither a correctly formed response for the JSON Wire Protocol (where "status" would be an integer), nor a correctly formed W3C response and without a correctly formed response, the w3c compatible cannot be used.
This revision and this commit addressed this issue.
This usecase
Presumably you are using ChromeDriver v75.x with Chrome v75.x and in case you are still seeing the error, you need to pass the ExperimentalOption w3c as true explicitly as follows:
Ruby code sample:
capabilities = { "chromeOptions" => {'w3c' => true} }
Java code sample:
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class W3c {
public static void main(String[] args) throws Exception {
ChromeOptions opt = new ChromeOptions();
opt.setExperimentalOption("w3c", true);
ChromeDriver driver = new ChromeDriver(opt);
driver.get("https://www.google.co.in");
}
}
Python code sample:
from selenium import webdriver
opt = webdriver.ChromeOptions()
opt.add_experimental_option('w3c', True)
driver = webdriver.Chrome(chrome_options=opt)
driver.get('https://www.google.co.in')
Update
Till ChromeDriver v74.x, Chrome and ChromeDriver combo was running in w3c mode by default but there was bug with in the chromedriver/server/http_handler.cc. As per the details in goog:chromeOptions.w3c=false doesn't work for POST request with empty body:
Method HttpHandler::HandleCommand checks the value of the kW3CDefault constant instead of session goog:chromeOptions.w3c value. As a result, JSON Wire protocol support was broken, where POST requests with an empty body are allowed.
JSON Wire protocol will be in demand until displayed endpoint is resumed in the w3c mode. It should be noted that W3C WebDriver specification doesn't forbid the use of 'displayed' endpoint and this feature is actively used in some APIs.
As Is Element Displayed command is not part of W3C spec, but is still used by some APIs, and its functionality can be difficult to replicate in those APIs. This Change List [revision and commit] re-enables this command in W3C mode to ease transition to W3C mode.
#John have already confirmed us to expect an update to ChromeDriver v75.0 tomorrow with the fix.
For the Javascript people (I specifically use WebdriverIO) make sure you use 'goog:chromeOptions'
capabilities: {
browserName: 'chrome',
'goog:chromeOptions': {
'w3c': false
}
}
Else you'll get
unknown error: Illegal key values seen in w3c capabilities: [chromeOptions]
After doing options = Selenium::WebDriver::Chrome::Options.new
you can do options.add_option('w3c', false)
I'm facing the same issue.
I tried to disable using capabilities = Selenium::WebDriver::Remote::Capabilities.chrome({ "chromeOptions" => {'w3c' => false} }) but it didn't work.
Then I changed to capabilities = { "chromeOptions" => {'w3c' => false} } and now it works.
Maybe it can help you.
This is how it can be done in Behat with Mink: #behat #mink
Behat\MinkExtension:
base_url: "your_site_url"
browser_name: 'chrome'
goutte: ~
javascript_session: selenium2
selenium2:
wd_host: http://127.0.0.1:4444/wd/hub
capabilities:
browser: chrome
extra_capabilities:
chromeOptions:
args: ['--headless', '--disable-gpu']
w3c: false
PHP Behat-Mink-Selenium users see this post for information:
https://medium.com/#alex.designworks/chromedriver-75-enforces-w3c-standard-breaking-behat-tests-460cad435545
and GitHub issue https://github.com/minkphp/MinkSelenium2Driver/issues/293
As of this post, the "workaround" is to fall back to Chrome 74 for those using Behat-Mink-Selenium.
{
'platformName':'Android',
'platformVersion':'8.0.0',
'deviceName':'Samsung Galaxy S9',
'deviceType':'Phone',
'nativeWebTap': 'True',
'browser' : 'Chrome',
"goog:chromeOptions": {'w3c': False}
}
use goog:chromeOptions options to set w3c True or False. on console you will see the same getting passed.
I recently upgraded appium to 1.18 , using chromeDriver version 84 and my chrome browser version is also 84. I use appium python library to start a browser. My capabilities are like below but I get error -"WebDriverException: Message: 'chromeOptions' must be of type object". Please let me know whats wrong with my capabilities.
{
'platformName':'Android',
'platformVersion':'8.0.0',
'deviceName':'Samsung Galaxy S9',
'deviceType':'Phone',
'nativeWebTap': 'True',
'browser' : 'Chrome',
'chromeOptions' : '{args: [ 'w3c : false']}'
}
Protractor creates a brand new Chrome profile every time it runs. So what i want to do it will enable popup for chrome browser every time when protractor test runs.
I don't want to use existing profile.Is there any way to do ?
You can create instance of chrome custom profile and it can be passed to capabilities.
export const chromeProfile = {
browserName : 'chrome',
maxInstances: 1,
chromeOptions: {
args: [
// mention list of all setting for chrome browser
//For example following two lines disable chrome popup
'disable-infobars=true',
'--disable-popup-blocking'
],
prefs: {
// disable password popup
'credentials_enable_service': false
}
}
};
I run a test suite locally that takes about 15 minutes. During this time it's impossible to get any work done because every feature spec brings the chrome window to the front. Is there a configuration option to avoid this, to NOT bring the capybara/selenium window to the front?
This is my current config:
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app,
browser: :chrome,
desired_capabilities: {
"chromeOptions" => {
"args" => %w{ window-size=1740,768 }
}
}
)
end
Capybara.server_port = 57124
Capybara.app_host = "http://localhost:#{Capybara.server_port}" # S3 accesss control blocks default capybara 127.0.0.1
Capybara.default_max_wait_time = 10 #default is 2
You can't if you want/need to run it in non-headless mode, but if you run in headless mode you won't have that issue.
Every time my webdriver tests login into the application, 'Do you want chrome to save your password' pop up appears.. Is there a way to avoid this??
Please help.
Thanks,
Mike
You need to configure the following chrome driver options:
chromeOptions: {
prefs: {
'credentials_enable_service': false,
'profile': {
'password_manager_enabled': false
}
}
}
I'm using Python, and this worked for me:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_experimental_option('prefs', {
'credentials_enable_service': False,
'profile': {
'password_manager_enabled': False
}
})
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get('https://google.com')
Just add these preferences to your chrome driver options:
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("credentials_enable_service", false);
prefs.put("password_manager_enabled", false);
options.setExperimentalOption("prefs", prefs);
Yeah I just found the answer. I had to look into the Chrome's user data directory and find all the available chromeOptions the Preferences file. I'm on Centos 7 so the path looks like this:
~/.config/google-chrome/Default/Preferences
In order to remove the save password dialog, the config JSON chromeOptions section needs to have this:
chromeOptions: {
prefs: {
profile: {
password_manager_enabled: false
}
}
}
It really makes me happy that I have finally found these options, however, it still is disappointing that google or selenium didn't list all the configurable preferences.
Thanks to #karanvir Kang comment above, I added the following to my conf.js which I use when I call protractor. Example
protractor tests/conf.js --specs /tests/e2e/myspec.spec.js
And in my conf.js
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
seleniumPort: '4455',
baseUrl: url,
directConnect: false,
//getMultiCapabilities: helper.getFirefoxProfile,
capabilities: {
browserName: 'chrome',
chromeOptions: {
prefs: {
'credentials_enable_service': false,
'profile': {
'password_manager_enabled': false
}
},
args: [
'--disable-cache',
'--disable-application-cache',
'--disable-offline-load-stale-cache',
'--disk-cache-size=0',
'--v8-cache-options=off'
]
}
},
You can also start the chromedriver in incognito mode to stop the infobars from appearing. Please note that the experience will be like the incognito mode. Command will be
chrome.exe --incognito if you are running from command line
you can add --incognito to chromeswitch array for executing from webdriver.
To provide a more complete picture, here is a working configuration for Watir in a Selenium Grid:
RSpec.configure do |config|
config.before :all do
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: {
prefs: {
'credentials_enable_service': false,
'profile': {
'password_manager_enabled': false
}
}
}
)
#browser = Watir::Browser.new(
:remote,
url: "http://#{ENV.fetch('HUB_HOST')}/wd/hub",
desired_capabilities: capabilities
)
end
config.after :all do
#browser&.close
end
end
See a full proof of concept on github at docker-grid-watir.
I know this is pretty old, it has been answered correctly and all. Just wanted to give my 5 cents. If you are using Robot Framework, bellow is the way to do it.
open-browser
${chrome_options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys
${cred_dict}= Create Dictionary credentials_enable_service=${FALSE}
Call Method ${chrome_options} add_experimental_option prefs ${cred_dict}
Create Webdriver Chrome chrome chrome_options=${chrome_options}