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

后端 未结 8 1743
梦谈多话
梦谈多话 2020-11-27 05:41

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, seleniu

相关标签:
8条回答
  • 2020-11-27 06:26

    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
    
    0 讨论(0)
  • 2020-11-27 06:28

    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]
    
    0 讨论(0)
  • 2020-11-27 06:29

    After doing options = Selenium::WebDriver::Chrome::Options.new you can do options.add_option('w3c', false)

    0 讨论(0)
  • 2020-11-27 06:34

    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.

    0 讨论(0)
  • 2020-11-27 06:35

    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

    75_76


    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.

    0 讨论(0)
  • 2020-11-27 06:39
    { 
      '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.

    0 讨论(0)
提交回复
热议问题