Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛 Bug]: [java] Cannot instantiate ChromeDriver on Windows using selenium 4.16 #13261

Closed
jstefek opened this issue Dec 7, 2023 · 26 comments
Closed
Labels
C-rust I-defect I-logging Applied to issues where logging information would help troubleshoot

Comments

@jstefek
Copy link

jstefek commented Dec 7, 2023

What happened?

I cannot instantiate ChromeDriver on selenium 4.16 on Windows 11.


Note: I was mainly focused to use version 4.16 to get over the bug #13091, which should be resolved by d1787a9 . On linux it seems to work correctly, but not on Windows.

How can we reproduce the issue?

Set up a simple maven project. Using just Selenium java.

    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.16.0</version>
        </dependency>
    </dependencies>

with one executable main method:

import org.openqa.selenium.chrome.ChromeDriver;

public class Main {
    public static void main(String[] args) {
        ChromeDriver chromeDriver = new ChromeDriver();
        chromeDriver.quit();
    }
}

Relevant log output

Using selenium 4.16 I get following error:

Exception in thread "main" org.openqa.selenium.remote.NoSuchDriverException: Unable to obtain: Capabilities {browserName: chrome, goog:chromeOptions: {args: [], extensions: []}}, error Command failed with code: -1073741701, executed: [--browser, chrome, --output, json]

Build info: version: '4.16.0', revision: '15400459dd*'
System info: os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '21.0.1'
Driver info: driver.version: ChromeDriver
	at org.openqa.selenium.remote.service.DriverFinder.getPath(DriverFinder.java:25)
	at org.openqa.selenium.remote.service.DriverFinder.getPath(DriverFinder.java:13)
	at org.openqa.selenium.chrome.ChromeDriver.generateExecutor(ChromeDriver.java:100)
	at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:89)
	at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:84)
	at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:73)
	at org.example.Main.main(Main.java:8)
Caused by: org.openqa.selenium.WebDriverException: Command failed with code: -1073741701, executed: [--browser, chrome, --output, json]

Build info: version: '4.16.0', revision: '15400459dd*'
System info: os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '21.0.1'
Driver info: driver.version: ChromeDriver
	at org.openqa.selenium.manager.SeleniumManager.runCommand(SeleniumManager.java:157)
	at org.openqa.selenium.manager.SeleniumManager.getDriverPath(SeleniumManager.java:299)
	at org.openqa.selenium.remote.service.DriverFinder.getPath(DriverFinder.java:22)
	... 6 more

Using selenium 4.15 all works as expected.

Operating System

Windows 11

Selenium version

4.16

What are the browser(s) and version(s) where you see this issue?

Chrome 120

What are the browser driver(s) and version(s) where you see this issue?

from SeleniumManager

Are you using Selenium Grid?

no

Copy link

github-actions bot commented Dec 7, 2023

@jstefek, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@jstefek jstefek changed the title [🐛 Bug]: Cannot instantiate ChromeDriver on Windows [java] [🐛 Bug]: Cannot instantiate ChromeDriver on Windows using selenium 4.16 [java] Dec 7, 2023
@jstefek jstefek changed the title [🐛 Bug]: Cannot instantiate ChromeDriver on Windows using selenium 4.16 [java] [🐛 Bug]: [java] Cannot instantiate ChromeDriver on Windows using selenium 4.16 Dec 7, 2023
@diemol
Copy link
Member

diemol commented Dec 7, 2023

@joerg1985 @bonigarcia seems the issue is now happening in non Docker environments?

@titusfortner titusfortner added the I-logging Applied to issues where logging information would help troubleshoot label Dec 7, 2023
Copy link

github-actions bot commented Dec 7, 2023

We need more information about this issue in order to troubleshoot.

Please turn on logging and re-run your code. Information on how to adjust logs for your language can be found in our
Troubleshooting documentation.

@letskodeit
Copy link

@titusfortner
Can you please let me know how to enable logging?
I referred to the documentation and tried to enable. I followed these steps:

Downloaded the dependency using this:

<dependency>
  <groupId>com.titusfortner</groupId>
  <artifactId>selenium-logger</artifactId>
  <version>2.3.0</version>
</dependency>

Added this line in the code before initializing the driver
SeleniumLogger.enable();

Example:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;

import com.titusfortner.logging.SeleniumLogger;

public class MSEdgeDriverDemo {
	public static void main(String[] args) {
		
		SeleniumLogger.enable();
		
		WebDriver driver = new EdgeDriver();
		driver.manage().window().maximize();
		driver.get("https://www.letskodeit.com");
		driver.quit();
	}
}

I still see the same error in Console:

2023-12-07 11:12:26 FINE Selenium [SeleniumManager getBinary] Selenium Manager binary found at: C:\Users\aniltomar\.cache\selenium\manager\0.4.16\selenium-manager.exe 
2023-12-07 11:12:26 FINE Selenium [SeleniumManager runCommand] Executing Process: [--browser, MicrosoftEdge, --output, json, --debug] 
2023-12-07 11:12:27 FINE Selenium [ExternalProcess] completed to copy the output of process 4848 
Exception in thread "main" org.openqa.selenium.remote.NoSuchDriverException: Unable to obtain: Capabilities {browserName: MicrosoftEdge, ms:edgeOptions: {args: [], extensions: []}}, error Command failed with code: -1073741701, executed: [--browser, MicrosoftEdge, --output, json, --debug]

Build info: version: '4.16.1', revision: '9b4c83354e'
System info: os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.6'
Driver info: driver.version: EdgeDriver
	at org.openqa.selenium.remote.service.DriverFinder.getPath(DriverFinder.java:25)
	at org.openqa.selenium.remote.service.DriverFinder.getPath(DriverFinder.java:13)
	at org.openqa.selenium.edge.EdgeDriver.generateExecutor(EdgeDriver.java:72)
	at org.openqa.selenium.edge.EdgeDriver.<init>(EdgeDriver.java:61)
	at org.openqa.selenium.edge.EdgeDriver.<init>(EdgeDriver.java:57)
	at org.openqa.selenium.edge.EdgeDriver.<init>(EdgeDriver.java:49)
	at org.openqa.selenium.edge.EdgeDriver.<init>(EdgeDriver.java:45)
	at basicweb.MSEdgeDriverDemo.main(MSEdgeDriverDemo.java:12)
Caused by: org.openqa.selenium.WebDriverException: Command failed with code: -1073741701, executed: [--browser, MicrosoftEdge, --output, json, --debug]

Build info: version: '4.16.1', revision: '9b4c83354e'
System info: os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.6'
Driver info: driver.version: EdgeDriver
	at org.openqa.selenium.manager.SeleniumManager.runCommand(SeleniumManager.java:157)
	at org.openqa.selenium.manager.SeleniumManager.getDriverPath(SeleniumManager.java:299)
	at org.openqa.selenium.remote.service.DriverFinder.getPath(DriverFinder.java:22)
	... 7 more

@joerg1985
Copy link
Member

@diemol I don't think this is related to the other issue, the other issue could not read the json output.
This one can not execute the selenium manager and returns a windows error code why.
-1073741701 is 0xC000007B aka. STATUS_INVALID_IMAGE_FORMAT

@joerg1985
Copy link
Member

joerg1985 commented Dec 7, 2023

@letskodeit could you please try to run the C:\Users\aniltomar\.cache\selenium\manager\0.4.16\selenium-manager.exe from the command line and check if it fails?
If not, add the --browser MicrosoftEdge --output json --debug as parameters and check if it is still working.

@titusfortner
Copy link
Member

@letskodeit yes, using that jar works! I was expecting to see SM logs, but looks like SM didn't even start in the first place.

As with @joerg1985, I'm curious what it shows when you run selenium-manager.exe with those parameters. Thanks.

@letskodeit
Copy link

@joerg1985 @titusfortner
This is what I see:

Screenshot 2023-12-07 at 6 29 58 PM

@joerg1985
Copy link
Member

@bonigarcia is the Visual C++ Redistributable for Visual Studio 2015-2022 mandatory to run a rust binary in windows?

@jstefek
Copy link
Author

jstefek commented Dec 8, 2023

Installed https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170#visual-studio-2015-2017-2019-and-2022 , did not help, still getting the 0xC000007B.
Also tried running as admin, same result.

@nvborisenko
Copy link
Member

Windows x86? :)

@jstefek
Copy link
Author

jstefek commented Dec 8, 2023

ic, ok.
I can confirm that installing the x86 version helped.
The manager produces desired output.
And the reproducer also works -- I am able to start Chrome browser and close it.

@letskodeit
Copy link

letskodeit commented Dec 8, 2023

C:\Users\aniltomar\.cache\selenium\manager\0.4.16\selenium-manager.exe --browser MicrosoftEdge --output json --debug
Ran command for version Selenium Manager version 0.4.15 without installing Visual C++ Redistributable for Visual Studio 2015-2022 and received the below output:

{
  "logs": [
    {
      "level": "DEBUG",
      "timestamp": 1702043695,
      "message": "msedgedriver not found in PATH"
    },
    {
      "level": "DEBUG",
      "timestamp": 1702043695,
      "message": "MicrosoftEdge detected at C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe"
    },
    {
      "level": "DEBUG",
      "timestamp": 1702043695,
      "message": "Running command: wmic datafile where name='C:\\\\Program Files (x86)\\\\Microsoft\\\\Edge\\\\Application\\\\msedge.exe' get Version /value"
    },
    {
      "level": "DEBUG",
      "timestamp": 1702043695,
      "message": "Output: \"\\r\\r\\n\\r\\r\\nVersion=119.0.2151.97\\r\\r\\n\\r\\r\\n\\r\\r\\n\\r\""
    },
    {
      "level": "DEBUG",
      "timestamp": 1702043695,
      "message": "Detected browser: MicrosoftEdge 119.0.2151.97"
    },
    {
      "level": "DEBUG",
      "timestamp": 1702043695,
      "message": "Reading msedgedriver version from https://msedgedriver.azureedge.net/LATEST_RELEASE_119_WINDOWS"
    },
    {
      "level": "DEBUG",
      "timestamp": 1702043696,
      "message": "Required driver: msedgedriver 119.0.2151.97"
    },
    {
      "level": "DEBUG",
      "timestamp": 1702043696,
      "message": "msedgedriver 119.0.2151.97 already in the cache"
    },
    {
      "level": "INFO",
      "timestamp": 1702043696,
      "message": "Driver path: C:\\Users\\aniltomar\\.cache\\selenium\\msedgedriver\\win-arm64\\119.0.2151.97\\msedgedriver.exe"
    },
    {
      "level": "INFO",
      "timestamp": 1702043696,
      "message": "Browser path: C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe"
    }
  ],
  "result": {
    "code": 0,
    "message": "C:\\Users\\aniltomar\\.cache\\selenium\\msedgedriver\\win-arm64\\119.0.2151.97\\msedgedriver.exe",
    "driver_path": "C:\\Users\\aniltomar\\.cache\\selenium\\msedgedriver\\win-arm64\\119.0.2151.97\\msedgedriver.exe",
    "browser_path": "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe"
  }
}

Why is it working with version 0.4.15 and not with 0.4.16?

@chadlwilson
Copy link

Why is it working with version 0.4.15 and not with 0.4.16?

Possibly related to the change in #13134 I guess

As @nvborisenko and @jstefek realised above (but I didn't quite follow initially) , installing VC++ redistributable 14.38.33130 works - but only if you install the x86 version (even on an x64 system or arm64 system).

It looks it's linked to the x86 version (i686 -> x86 -> 32-bit) which is possibly where folks are going wrong installing the runtime, and is probably a less common runtime variant to already be installed on folks' systems for other reasons.

image

Bit of a shame that the extra hidden runtime dependency is needed (especially to x86 arch), but perhaps there are other considerations here.

@letskodeit
Copy link

letskodeit commented Dec 10, 2023

Does it mean 4.15 version doesn't need Visual C++ Redistributable for Visual Studio 2015-2022?

@chadlwilson
Copy link

chadlwilson commented Dec 10, 2023

Does it mean 4.15 version doesn't need Visual C++ Redistributable for Visual Studio 2015-2022?

As far as I can see, 4.15 does not need the redist - which is why it worked as you posted above?

To build with the Microsoft Visual C++ toolchain as in #13134 and statically link the C runtime so that users don't need to install the redistributable I believe it would require the devs to configure the rust build with something like rustflags = ["-C", "target-feature=+crt-static"] but haven't tried it myself to see if it works, and how much it increases the binary size by. Some discussion is at https://users.rust-lang.org/t/windows-binaries-vcruntime140-dll-not-found-unless-crt-static/94517

@letskodeit
Copy link

@titusfortner @chadlwilson
Is that a new requirement with version 4.16 listed in changelogs or this is still a bug which needs to be fixed to remove the requirement?

@titusfortner
Copy link
Member

I think there was a change to how we built for windows in 4.16 to fix a different problem. We need to hear back from @bonigarcia on this one.

@bonigarcia
Copy link
Member

Sorry for the inconvenience. Installing Visual C++ should not be necessary. It seems the Rust flags -Ctarget-feature=+crt-static are required to avoid the problem related to Visual C++ Redistributable for Visual Studio 2015-2022. In fact, these flags were already available in former versions of Selenium Manager, but they were not in Selenium 4.15 and 4.16.

I created PR #13281 to restore these flags when building Selenium Manager.

If anyone needs the binaries built with that flag, it can be downloaded from here:

https://github.com/SeleniumHQ/selenium/actions/runs/7166910213

@letskodeit
Copy link

@bonigarcia
Thanks for the clarification. Does it mean, we will have a fix in future versions?

@bonigarcia
Copy link
Member

Thanks for the clarification. Does it mean, we will have a fix in future versions?

Yes.

@titusfortner
Copy link
Member

Fixes are in trunk. Thanks.

@benken-parasoft
Copy link

How soon can we expect 4.17? Or could a selenium-java 4.16.2 be pushed out sooner just to fix this regression?

@titusfortner
Copy link
Member

You can use nightly if you need. https://www.selenium.dev/downloads/#nightly

@benken-parasoft
Copy link

You can use nightly if you need. https://www.selenium.dev/downloads/#nightly

I see that 4.17.0 was published with commit for "Restore rust flags" mentioned in the release notes. Thanks!

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Feb 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C-rust I-defect I-logging Applied to issues where logging information would help troubleshoot
Projects
None yet
Development

No branches or pull requests

9 participants