Problem installing and running Selenium WebDriver using Java on a Mac

2,736 views
Skip to first unread message

Old Keksi

unread,
Mar 20, 2022, 5:31:22 AM3/20/22
to Selenium Users
I'm trying to install and run Selenium WebDriver using Java on a Mac. My favourite IDE is IntelliJ IDEA. When I try this:

public class TestImplWithoutWebDriverManager implements TestingConstants
{
    static public void main(String... args)
    {
        String chromeDriverLibPath = "./lib/chromedriver";
        File chromeDriverLib = new File(chromeDriverLibPath);
        System.out.println(chromeDriverLib.exists());
        System.out.println(chromeDriverLib.canRead());
        System.setProperty("webdriver.chrome.driver", chromeDriverLibPath);
        ChromeDriver chromeDriver = new ChromeDriver();
        chromeDriver.navigate().to(MyTestHomePage);
    }
}

I get this console output:

true
true
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:576)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:245)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:161)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:137)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:125)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:106)
    at TestImplWithoutWebDriverManager.main(TestImplWithoutWebDriverManager.java:26)
Caused by: org.openqa.selenium.WebDriverException: Driver server process died prematurely.
Build info: version: '4.1.2', revision: '9a5a329c5a'
System info: host: 'Lemmis-MacBook-Pro-16.local', ip: '192.168.0.2', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '12.2.1', java.version: '1.8.0_312'
Driver info: driver.version: FirefoxDriver
    at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:226)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:98)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:558)
    ... 6 more

Process finished with exit code 1

... where the content of the .lib folder is:

-rwxr-xr-x@ 1 lemmi  staff  17775332 Jun  4  2013 chromedriver
-rwxr-xr-x@ 1 lemmi  staff   4261264 Sep 16 11:55 geckodriver
-rwxr-xr-x@ 1 lemmi  staff  18016880 Mar 10 08:06 msedgedriver

... what is exactly what I extracted from:

-rw-r--r--@ 1 lemmi  staff   7614601 Mar 14 14:48 chromedriver_mac32.zip
-rw-r--r--@ 1 lemmi  staff   9886384 Mar 14 15:12 edgedriver_mac64.zip
-rw-r--r--@ 1 lemmi  staff   1854001 Mar 14 14:49 geckodriver-v0.30.0-macos.tar.gz

What am I missing out?

SiKing

unread,
Mar 21, 2022, 11:43:14 AM3/21/22
to Selenium Users
This is very confusing. How do you go from:

ChromeDriver chromeDriver = new ChromeDriver();

to:

    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:106)
    at TestImplWithoutWebDriverManager.main(TestImplWithoutWebDriverManager.java:26)

Show the other 26 lines of your code.

Old Keksi

unread,
Mar 21, 2022, 12:08:52 PM3/21/22
to Selenium Users
Hi SiKing

Thanx for your note. I have to correct my console output. There it says something about a FirefoxDriver which is not addressed in the source code at all. The console output and the source code were not in sync. Here's the correct source code:

import framework.TestingConstants;
import org.openqa.selenium.chrome.ChromeDriver;

import java.io.File;


public class TestImplWithoutWebDriverManager implements TestingConstants
{
    static public void main(String... args)
    {
        String chromeDriverLibPath = "./lib/chromedriver";
        File chromeDriverLib = new File(chromeDriverLibPath);
        System.out.println(chromeDriverLib.exists());
        System.out.println(chromeDriverLib.canRead());
        System.setProperty("webdriver.chrome.driver", chromeDriverLibPath);
        ChromeDriver chromeDriver = new ChromeDriver();
        chromeDriver
            .navigate()
            .to(MyTestHomePage);
    }
}

and the correct console output:

true
true
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:576)
        at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:245)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:161)
        at org.openqa.selenium.chromium.ChromiumDriver.<init>(ChromiumDriver.java:108)
        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:106)
        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:93)
        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:48)
        at TestImplWithoutWebDriverManager.main(TestImplWithoutWebDriverManager.java:15)

Caused by: org.openqa.selenium.WebDriverException: Driver server process died prematurely.
Build info: version: '4.1.2', revision: '9a5a329c5a'
System info: host: 'Lemmis-MacBook-Pro-16.local', ip: '192.168.0.2', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '12.3', java.version: '1.8.0_312'
Driver info: driver.version: ChromeDriver

        at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:226)
        at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:98)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:558)
        ... 7 more


Process finished with exit code 1

Veena

unread,
Mar 21, 2022, 12:51:20 PM3/21/22
to Selenium Users

1. Check whether mentioned Correct driver exe path.
2. keep the Path till extension like ./lib/chromedriver.exe
3. make sure downloaded the correct version of the exe file to match your local chrome browser.

I suggest overcoming all these steps using the WebDriverManager opensource project.

WebDriverManager.chromedriver().setup();
WebDriver driver= new ChromeDriver();

SiKing

unread,
Mar 21, 2022, 2:04:48 PM3/21/22
to Selenium Users
public class TestImplWithoutWebDriverManager implements TestingConstants

As an initial experiment can you drop implementing TestingConstants, since I have no idea what that is.

Also, what do you get if you manually run ` ./lib/chromedriver --version` from the commandline?

Old Keksi

unread,
Mar 21, 2022, 4:04:43 PM3/21/22
to Selenium Users
Hi Veena

Many thanx for your reply.

To 1: The file path is ok. That's what the two "true" in the console output show. They show whether the lib file is there and whether it is readable.
To 2: There are no ".exe" extensions since this is a Macintosh computer, not a windows computer:
... where the content of the .lib folder is:
-rwxr-xr-x@ 1 lemmi  staff  17775332 Jun  4  2013 chromedriver
-rwxr-xr-x@ 1 lemmi  staff   4261264 Sep 16 11:55 geckodriver
-rwxr-xr-x@ 1 lemmi  staff  18016880 Mar 10 08:06 msedgedriver
To 3: I downloaded the files a couple of days ago from https://www.selenium.dev/documentation/webdriver/getting_started/install_drivers/
They are up-to-date.

WebDriverManager: Due to security policy, it is not possible to let a class get stuff from the internet. The libs must already be in place locally.

Old Keksi

unread,
Mar 21, 2022, 4:09:12 PM3/21/22
to Selenium Users
ACK. TestingConstants is a part of my testing suite. It can easily be omitted, only then the Constant "MyTestHomePage" in the very last line of code must be replaced by an existing URL String.

Old Keksi

unread,
Mar 22, 2022, 2:55:57 AM3/22/22
to Selenium Users
Hm... when I run "./lib/chromedriver --version", he says:

zsh: bad CPU type in executable: lib/chromedriver

What does that mean?

⇜Krishnan Mahadevan⇝

unread,
Mar 22, 2022, 3:21:11 AM3/22/22
to Selenium Users
Sounds like you are on a MAC.

Can you just use brew to install chromedriver ? That would also ensure that the binary is automatically added to your PATH variable and you don't need to be doing anything extra.

You may have to restart your IDE after installing chromedriver via homebrew


After installing try just running chromedriver. You should see something like this.

~ chromedriver
Starting ChromeDriver 99.0.4844.51 (d537ec02474b5afe23684e7963d538896c63ac77-refs/branch-heads/4844@{#875}) on port 9515
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/21b669b8-0f5f-46a5-93fe-9ba64c7c8b7bn%40googlegroups.com.

SiKing

unread,
Mar 22, 2022, 1:46:36 PM3/22/22
to Selenium Users
> Hm... when I run "./lib/chromedriver --version", he says:

> zsh: bad CPU type in executable: lib/chromedriver

> What does that mean?

This means you found your problem! You installed an invalid/corrupted executable.
You can install the correct one from here https://chromedriver.chromium.org/downloads
Or follow the advice from Krishnan Mahadevan.

Good luck.

Old Keksi

unread,
Mar 22, 2022, 2:56:57 PM3/22/22
to Selenium Users
Krishan & SiKing

All fine. Now it works as expected!

At first I installed Homebrew and with it then chromedriver. It worked.

Then I downloaded from <chromedriver.storage.googleapis.com/index.html?path=99.0.4844.51> the 64-bit-version of the chromedriver, put it into my ./lib folder and it worked as well.

Many thanks to all of you once more!

Best regards from Ol'Keksi
Reply all
Reply to author
Forward
0 new messages