How to turn off w3c in chromedriver to address the error unknown command: Cannot call non W3C standard command while in W3C - selenium

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']}'
}

Related

How do I correct this Selenium initialisation command deprecation warning?

Using Rails 6 I'm trying to set up selenium in headless mode for system tests, I'm using this statement in application_system_test_case.db:
driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400]
(according to Agile Web Dev Rails 6 tutorial)
but it gives me this deprecation warning:
Selenium [DEPRECATION] [:browser_options] :options as a parameter for driver initialization is deprecated. Use :capabilities with an Array of value capabilities/options if necessary instead.
I've done some searching in Selenium docs but I my basic code skills still leave me unclear as to how I should correct this. Can anyone advise how I can correct this?
(My amateur guesswork trials of things like:
driven_by :selenium, :capabilities['headless_chrome', 'screen_size: 1400, 1400']
all result in errors)
Updated version for the new warning with options instead of capabilities
Capybara.register_driver :headless_chrome do |app|
options = Selenium::WebDriver::Chrome::Options.new
options.add_argument('--headless')
Capybara::Selenium::Driver.new(
app,
browser: :chrome,
options: options
)
end
Capybara.register_driver :chrome do |app|
options = Selenium::WebDriver::Chrome::Options.new
Capybara::Selenium::Driver.new(
app,
browser: :chrome,
options: options
)
end
Capybara.default_driver = :chrome
In Selenium 4, the options must be passed in array capabilities:
def selenium_options
options = Selenium::WebDriver::Chrome::Options.new
options.add_argument('--headless')
options
end
# optional
def selenium_capabilities_chrome
Selenium::WebDriver::Remote::Capabilities.chrome
end
def driver_init
caps = [
selenium_options,
selenium_capabilities_chrome,
]
Selenium::WebDriver.for(:chrome, capabilities: caps)
end
driver = driver_init
I stumbled upon this thread a couple of times already. What was bothering to me were not only the deprecated messages, but also the puma server logs while launching the test suite. I've ended up fixing the deprecation warning and shutting the puma logs. Here's my current setup:
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
# provides devise methods such as login_session
include Devise::Test::IntegrationHelpers
# removes noisy logs when launching tests
Capybara.server = :puma, { Silent: true }
Capybara.register_driver :headless_chrome do |app|
options = Selenium::WebDriver::Chrome::Options.new(args: %w[headless window-size=1400,1000])
Capybara::Selenium::Driver.new(app, browser: :chrome, capabilities: options)
end
Capybara.register_driver(:chrome) do |app|
options = Selenium::WebDriver::Chrome::Options.new(args: %w[window-size=1400,1000])
Capybara::Selenium::Driver.new(app, browser: :chrome, capabilities: options)
end
ENV['HEADLESS'] ? driven_by(:headless_chrome) : driven_by(:chrome)
end
So you can launch tests, for instance, with:
HEADLESS=1 rails test:all
Suppress the warning
One line fix:
# rails_helper.rb
Selenium::WebDriver.logger.ignore(:browser_options)
Suggested here
OR
(probably) Any version of Capybara > 3.36.0
Edit: #silvia96 has 3.38.0 and still getting warning
It's quite a confusing bug because if you look at the Capybara driver registration you can see it already knows about using capabilities. The actual bug is because the Gem version test is set as ~ instead of >=. The fix is in main and any version of Capybara after 3.36.0 will, likely, fix it.
Combining the useful solutions from others, here's what mine looks like.
Remove puma logs, make headless chrome, ignore browser options error:
require "test_helper"
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium, using: :headless_chrome
Capybara.server = :puma, { Silent: true }
Selenium::WebDriver.logger.ignore(:browser_options)
end

Download file through Google Chrome RemoteWebDriver- headless mode in Linux using Selenium Java [duplicate]

I'm do me code in Cromedrive in 'normal' mode and works fine. When I change to headless mode it don't download the file. I already try the code I found alround internet, but didn't work.
chrome_options = Options()
chrome_options.add_argument("--headless")
self.driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=r'{}/chromedriver'.format(os.getcwd()))
self.driver.set_window_size(1024, 768)
self.driver.command_executor._commands["send_command"] = ("POST", '/session/$sessionId/chromium/send_command')
params = {'cmd': 'Page.setDownloadBehavior', 'params': {'behavior': 'allow', 'downloadPath': os.getcwd()}}
self.driver.execute("send_command", params)
Anyone have any idea about how solve this problem?
PS: I don't need to use Chomedrive necessarily. If it works in another drive it's fine for me.
First the solution
Minimum Prerequisites:
Selenium client version: Selenium v3.141.59
Chrome version: Chrome v77.0
ChromeDriver version: ChromeDriver v77.0
To download the file clicking on the element with text as Download Data within this website you can use the following solution:
Code Block:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("--headless")
options.add_argument("--window-size=1920,1080")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe', service_args=["--log-path=./Logs/DubiousDan.log"])
print ("Headless Chrome Initialized")
params = {'behavior': 'allow', 'downloadPath': r'C:\Users\Debanjan.B\Downloads'}
driver.execute_cdp_cmd('Page.setDownloadBehavior', params)
driver.get("https://www.mockaroo.com/")
driver.execute_script("scroll(0, 250)");
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button#download"))).click()
print ("Download button clicked")
#driver.quit()
Console Output:
Headless Chrome Initialized
Download button clicked
File Downloading snapshot:
Details
Downloading files through Headless Chromium was one of the most sought functionality since Headless Chrome was introduced.
Since then there were different work-arounds published by different contributors and some of them are:
Downloading with chrome headless and selenium
Python equivalent of a given wget command
Now the, the good news is Chromium team have officially announced the arrival of the functionality Downloading file through Headless Chromium.
In the discussion Headless mode doesn't save file downloads #eseckler mentioned:
Downloads in headless work a little differently. There's the Page.setDownloadBehavior devtools command to set a download folder. We're working on a way to use DevTools network interception to stream the downloaded file via DevTools as well.
A detailed discussion can be found at Issue 696481: Headless mode doesn't save file downloads
Finally, #bugdroid revision seems to have nailed the issue for us.
[ChromeDriver] Added support for headless mode to download files
Previously, Chromedriver running in headless mode would not properly download files due to the fact it sparsely parses the preference file given to it. Engineers from the headless chrome team recommended using DevTools's "Page.setDownloadBehavior" to fix this. This changelist implements this fix. Downloaded files default to the current directory and can be set using download_dir when instantiating a chromedriver instance. Also added tests to ensure proper download functionality.
Here is the revision and commit
From ChromeDriver v77.0.3865.40 (2019-08-20) release notes:
Resolved issue 2454: Headless mode doesn't save file downloads [Pri-2]
Solution
Update ChromeDriver to latest ChromeDriver v77.0 level.
Update Chrome to Chrome Version 77.0 level. (as per ChromeDriver v76.0 release notes)
Note: Chrome v77.0 is yet to be GAed/pushed for release so till then you can download and install a development build and test either from:
Chrome Canary
Latest build from the Dev Channel
Outro
However Mac OSX users have a wait for their pie as On Chromedriver, headless chrome crashes after sending Page.setDownloadBehavior on MacOSX.
Chomedriver Version: 95.0.4638.54
Chrome Version 95.0.4638.69
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("--headless")
options.add_argument("--start-maximized")
options.add_argument("--no-sandbox")
options.add_argument("--disable-extensions")
options.add_argument('--disable-dev-shm-usage')
options.add_argument("--disable-gpu")
options.add_argument('--disable-software-rasterizer')
options.add_argument("user-agent=Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; Microsoft; Lumia 640 XL LTE) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Mobile Safari/537.36 Edge/12.10166")
options.add_argument("--disable-notifications")
options.add_experimental_option("prefs", {
"download.default_directory": "C:\\link\\to\\folder",
"download.prompt_for_download": False,
"download.directory_upgrade": True,
"safebrowsing_for_trusted_sources_enabled": False,
"safebrowsing.enabled": False
}
)
What seemed to work was that I used "\\" instead of "/" for the address. The latter approach didn't throw any error, but didn't download any documents either. But, using double back slashes did the job.
For javascript use below code:
const chrome = require('selenium-webdriver/chrome');
let options = new chrome.Options();
options.addArguments('--headless --window-size=1500,1200');
options.setUserPreferences({ 'plugins.always_open_pdf_externally': true,
"profile.default_content_settings.popups": 0,
"download.default_directory": Download_File_Path });
driver = await new webdriver.Builder().setChromeOptions(options).forBrowser('chrome').build();
Then switch tabs as soon as you click the download button:
await driver.sleep(1000);
var Handle = await driver.getAllWindowHandles();
await driver.switchTo().window(Handle[1]);
This C# works for me
Note the new headless option https://www.selenium.dev/blog/2023/headless-is-going-away/
private IWebDriver StartBrowserChromeHeadlessDriver()
{
var chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("--headless=new");
chromeOptions.AddArgument("--window-size=1920,1080");
chromeOptions.AddUserProfilePreference("download.default_directory", downloadFolder);
var chromeDownload = new Dictionary<string, object>
{
{ "behavior", "allow" },
{ "downloadPath", downloadFolder }
};
var driver = new ChromeDriver(driverFolder, chromeOptions, TimeSpan.FromSeconds(timeoutSecs));
driver.ExecuteCdpCommand("Browser.setDownloadBehavior", chromeDownload);
return driver;
}
import pathlib
from selenium.webdriver import Chrome
driver = Chrome()
driver.execute_cdp_cmd("Page.setDownloadBehavior", {
"behavior": "allow",
"downloadPath": str(pathlib.Path.home().joinpath("Downloads"))
})
I don't think you should be using the browser for downloading content, leave it to Chrome developers/testers.
I believe you should rather get href attribute of the element you want to download and obtain it using requests library
If your site requires authentication you could fetch cookies from the browser instance and pass them to requests.Session.

:driver_opts is deprecated. Use :service with an instance of Selenium::WebDriver::Service instead

2019-06-19 15:44:43 WARN Selenium [DEPRECATION] :driver_opts is deprecated. Use :service with an instance of Selenium::WebDriver::Service instead.
Screenshot error, but continue to execute.
wrong number of arguments (given 0, expected 1)
2019-06-19 15:44:43 WARN Selenium [DEPRECATION] :driver_opts is deprecated. Use :service with an instance of Selenium::WebDriver::Service instead.
2019-06-19 15:44:43 WARN Selenium [DEPRECATION] :driver_opts is deprecated. Use :service with an instance of Selenium::WebDriver::Service instead.
visit in hook, after scenario +1s, #1s
2019-06-19 15:44:43 WARN Selenium [DEPRECATION] :driver_opts is deprecated. Use :service with an instance of Selenium::WebDriver::Service instead.
I've been using the below code snippet to init a session with old 'selenium-webdriver' v3.6.0 and got the above error:
Updated on June 23rd.
if Capybara.default_driver == :selenium
Capybara.register_driver :selenium do |app|
# In the block, we build up an `options` hash to pass to
# Capybara::Selenium::Driver.new(app, options)
# which in turn calls
# Selenium::WebDriver.for(options[:browser], options)
browser = Configuration.fetch('browser.type', :firefox)
options = {
browser: browser, # chrome
}
if Configuration.fetch('options.webdriver.use_hub', false)
{...}
elsif browser == :firefox
{...}
elsif browser == :chrome
chrome_logpath = "../chromedriver.log"
options[:service] = ::Selenium::WebDriver::Service.chrome(
args: {
verbose: true,
log_path: chrome_logpath,
}
)
chrome_options = Selenium::WebDriver::Chrome::Options.new
chrome_options.add_argument("user-agent='QA Test'")
chrome_options.add_option('w3c',false)
options[:options] = chrome_options
end
Capybara::Selenium::Driver.new(app, options)
end
end
After bumped that gem to v3.142.0 then I got that error. Tracing back to the Selenium Webdriver Changelog in https://github.com/SeleniumHQ/selenium/blob/master/rb/CHANGES then i found the following description, which might break the current code
3.141.592 (2019-04-18)
Chrome:
Added support for instantiating service class directly and moved all driver executable configuration there (command-line arguments, port, etc.)
Passing driver_opts, driver_path and port to driver initializer is now deprecated
so use Selenium::WebDriver::Service.chrome instead,
which allows to customize executable behavior in similar way.
Once initialized, this object can be passed as :service keyword
during driver initialization.
* Deprecated Chrome.driver_path= in favor of Service::Chrome.driver_path=
Googling for a while i found some results and workaround like using 'webdriver' gem but i don't like it that much.
So wonder if something that i can change my snippet above to adapt with that selenium-webdriver ver 3.142.0 and onwards? I'm using Capybara v3.18.0 at the moment.
Thanks everyone,
That's not an error, it's a deprecation warning. It's telling you that you will need to change your code before selenium-webdriver v4.0 is released. If you feel you must update your code today it would be something like
elsif browser == :chrome
options[:service] = ::Selenium::WebDriver::Service.chrome(
args: {
verbose: true,
log_path: "../chromedriver.log",
}
)
chrome_options = Selenium::WebDriver::Chrome::Options.new
# add user agent to that class options
chrome_options.add_argument("user-agent='QA Test'")
options[:options] = chrome_options
end
The other stuff you show
Screenshot error, but continue to execute.
wrong number of arguments (given 0, expected 1)
is something different and isn't coming from any of the code you're showing.

Test work properly on Chrome, not on Firefox

I wrote test using TestNG and selenium.
code...
actions.sendKeys(Keys.chord(Keys.CONTROL, "a"));
actions.sendKeys(Keys.BACK_SPACE);
actions.build().perform();
code...
I wanted to delete text in login window using these sendKeys, with DataProvider
#DataProvider(name = "inputs")
public Object[][] getData() {
return new Object[][]{
{"000000000", true},
{"000000000", true}
};
}
Html:
<div><input type="tel" class="valid TextInput-kJdagG iVdKHC" name="recoveryPhone" id="eb69ff0b-3427-6986-7556-b7af40ffb156" aria-describedby="eb69ff0b-3427-6986-7556-b7af40ffb156" value="+48 "></div>
Error message:
Unable to read VR
Path1523545392670 Marionette INFO Enabled via --marionette
1523545393744 Marionette INFO Listening on port 52644
1523545394180 Marionette WARN TLS certificate errors will be ignored for this session
Test work as I expected on Chrome, but on firefox these sendKeys not always mark the text, and clear this text. In project I have to use action class. Why the test runs differently?
Check this post https://github.com/mozilla/geckodriver/issues/665 against your versions (browser, browser driver, selenium etc which are always sensible to include in any question), it could be a known bug with the geckodriver.
The post includes a work around of creating the chord in a different way, using:
List<CharSequence> keyWithModifiers = new ArrayList<CharSequence>();
keyWithModifiers.add(Keys.CONTROL);
keyWithModifiers.add("a");
String ctrlA = Keys.chord(keyWithModifiers);
textFieldElem.sendKeys(ctrlA);
This approach worked for me using Selenium 3.7.1 Java bindings, gecko driver 0.18.0 (64 bit) and Firefox 57.0.2 - 59.0

How to ignore ssl certificate in codeception chrome headless browser?

I added in acceptance.suite.yml
chromeOptions:
args: ["--headless", "--disable-gpu","--test-type","--ignore-certificate-errors"],
but no luck? what can i do now
description edit:
When i start tests in headless mode they get stuck, in the _output file (fail.png) i get blank page. So i think that they get to "Insecure Connection" page and can't get through it, and my question is how to avoid that page
I suspect the argument you want is allow-insecure-localhost. This line worked for me to configure my acceptance.suite.yml file in CodeCeption.
- WebDriver:
url: xxx.com
window_size: false # disabled in ChromeDriver
port: 9515
browser: chrome
capabilities:
goog:chromeOptions:
args: ["allow-insecure-localhost","headless","start-maximized"]
This page lists all the options that chrome supports https://peter.sh/experiments/chromium-command-line-switches/#allow-insecure-localhost. Google themselves link to that (3rd party) page from their own page describing ChromeDriver config https://sites.google.com/a/chromium.org/chromedriver/capabilities.
Not sure if this already answered but according to codeception documentation
https://codeception.com/docs/modules/WebDriver
modules:
enabled:
- WebDriver:
config:
url: 'http://localhost/'
browser: chrome
capabilities:
acceptInsecureCerts: true
This works for me,
ChromeOptions options = (ChromeOptions) caps.getCapability(ChromeOptions.CAPABILITY);
options.addArguments("--headless", "--disable-gpu", "--window-size=1366,768", "--no-sandbox");
caps.setAcceptInsecureCerts(true);
Please try following code .
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-dev-shm-usage");
options.addArguments("--no-sandbox");
options.addArguments("--headless", "--window-size=1920,1200", "--ignore-certificate-errors");
options.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
options.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);
driver = new ChromeDriver(options);