bonigarcia / webdrivermanager

Automated driver management and other helper features for Selenium WebDriver in Java
https://bonigarcia.dev/webdrivermanager/
Apache License 2.0
2.56k stars 673 forks source link

Opera driver deprecated by Selenium project - they recommend using Chrome driver #808

Closed ibodog closed 2 years ago

ibodog commented 2 years ago

Description of the problem: Selenium project has deprecated Opera Options and recommend using Chrome driver and set the binary to Opera (https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/opera/OperaOptions.html). This causes problems because version of Opera lags Chromium and Chrome driver latest is sometimes not compatible with Opera.

While it is possible to explicitly specify the Chrome Driver version to work around this issue it impacts the "niceness" of using WebDriverManager so that "it just works". :)

Browser and version: example: Opera 85.0.4341.28 is based on Chromium 99.0.4844.84 and current Chromium driver doesn't support < v100.

Operating system: any OS

WebDriverManager version: 5.1.0

WebDriverManager call: Opera related

WebDriverManager traces: N/A

Error log: example error when not specifying any webdriver versions for the latest Chrome Driver and trying to use it per the instructions of the Selenium project:

org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: session not created: This version of ChromeDriver only supports Chrome version 100 Current browser version is 99.0.4844.84 with binary path /Applications/Opera.app/Contents/MacOS/Opera Build info: version: '4.1.3', revision: '7b1ebf28ef'

bonigarcia commented 2 years ago

Yes, I'm working on this. The master branch already contains that "it just work" thing for OperaDriver. It will be available for next version of WebDriverManager. You can see a test example here.

bonigarcia commented 2 years ago

You have another simpler way of using Opera with the latest version of WebDriverManager here.

bonigarcia commented 2 years ago

This is already available in WebDriverManager 5.1.1, just released.

ibodog commented 2 years ago

WebDriverManager.operadriver() is not using Chrome driver, but old Opera driver still in the new version 5.1.1.

In my project I set up all browsers to run as remote webdriver. Local runs configure a driver service. Selenium grid runs omit the local driver service. This still uses the Opera driver (that throws org.openqa.selenium.UnsupportedCommandException: getElementDomAttribute errors for some W3C compliant calls):

      WebDriverManager  wdm = WebDriverManager.operadriver();
      wdm.setup();
      File driverExecutable = new File(wdm.getDownloadedDriverPath());
      DriverService driverService =
          new OperaDriverService.Builder()
              .usingDriverExecutable(driverExecutable)
              .usingAnyFreePort()
              .build();

I can workaround by substituting Chrome driver, adding Chromium version from Opera, and specifying Opera browser path in the Chrome options. Something like this:

      WebDriverManager  wdm = WebDriverManager.chromedriver();
      wdm.browserVersion("98");
      wdm.setup();
      File driverExecutable = new File(wdm.getDownloadedDriverPath());
      DriverService driverService =
          new OperaDriverService.Builder()
              .usingDriverExecutable(driverExecutable)
              .usingAnyFreePort()
              .build();
        ((ChromeOptions) caps).setBinary(WebDriverManager.operadriver().getBrowserPath().get().toFile());
        WebDriver  webDriver = new RemoteWebDriver(driverService.getUrl(), (ChromeOptions) caps);

Note that OperaOptions are deprecated in latest Selenium as mentioned in this issue's original description.