How to Install Selenium for Chrome in Windows 11

--

OBJECTIVE: Install Selenium for Chrome browser in Windows 11

Welcome to the 2nd article of my Selenium course review! After introductions were done, another instructor took over to explain the installation process. This article will cover the procedure with some of the questions/concerns brought forth. I’m also including some of my own insights.

The 1st major step in learning Selenium is simply to install it. Since Selenium is open source software (OOS), it has been updated to be compatible with several browsers. The outlined procedure below is generally the same, but adjustments are necessary as per browser. Here, we’ll just be covering the Chrome browser.

OUTLINE:
[Section A] VERIFY VERSIONS
[Section B] DOWNLOADS
[Section C] CONFIRM JDK, SET ENVIRONMENT VARIABLES
[Section D] DOWNLOAD BROWSER, SELENIUM JARS, WEBDRIVER
[Section E] CREATE ECLIPSE PROJECT, PACKAGE, CLASS, INSTALL JARS
[Section F] CODE TO LAUNCH AUTOMATED BROWSER
[Section G] TROUBLESHOOTING TIPS

Let’s begin by verifying our environment. In this example, we’ll be installing on a 64-bit Windows 11 OS for the Chrome browser.

[Section A] VERIFY VERSIONS
Today, we’ll be verifying/installing/setting up the following:
[1] OS version (MS Windows 64bit)
[2] JDK19 version (Command Prompt)
[3] Environment variables
[4] Browser: Chrome> Settings> Help/About> Version 110.0.5481.178 (Official Build)(64-bit)
[5] Selenium (latest Stable: 4.8.1)
[6] Match driver for browser/OS (ChromeDriver 110.0.5481.77)
[7] Eclipse IDE for Java and Web Developers (latest 2022 12R)

+ [1] Confirm OS version (32-bit vs 64-bit)
> Press [Windows] button or right-click the Windows logo in the standard bottom-left corner
> System (left-click)
> View About section
> View System type: 64-bit operating system, x64-based processor

Another way to confirm is by inspecting the folder structure. You have a 64-bit system if you can see these below; and you have a 32-bit system if you don’t see these:
C:\Program Files (x86)
C:\Windows\SysWOW64
*See https://tarma.com/support/im9/using/pages/typicalpaths.htm

[Section B] DOWNLOADS
+ List of site links to download from:
*Recommend downloads/zip files be extracted into a designated folder on your Desktop
* Expect to register an email/password for an Oracle account to download JDK19 (latest)

> Once you have your credentials, get Java SE Development Kit (JDK19) by searching “download jdk for windows” or click:
https://www.oracle.com/in/java/technologies/downloads/#jdk19-windows
> Choose the Windows version with which you’re most comfortable (*.zip, *.exe, *.msi)
*Typically, .msi files are considered safer than .exe, which can be rejected by anti-virus software
> Extract .zip file to your desired location
> Get Selenium 4.8.1 (latest for Java)
https://www.selenium.dev/downloads/
* Compatible browsers (6) and Operating Systems (3 Platforms: Linux, macOS, & MS Windows) are listed at bottom of same page: Firefox, Internet Explorer, Safari, Opera, Chrome, & Edge
> Get latest version of Chrome from: https://www.google.com/chrome/
> From the bottom of the selenium downloads page, expand the Browsers section, click Chrome’s documentation link, then get matching driver or go here:
Chrome (ChromeDriver)= https://chromedriver.chromium.org/
> Get Eclipse IDE for Java and Web Developers (latest 2022 12R) from links below or search “download eclipse 12 jee”
* Determine matching version for your OS version:
https://www.eclipse.org/downloads/packages/
https://www.eclipse.org/downloads/packages/release/2022-12/r/eclipse-ide-enterprise-java-and-web-developers

[Section C] CONFIRM JDK, SET ENVIRONMENT VARIABLES
* Return to this section if you still need to download the JDK (as per Section B)
+ [2] Confirm JDK Version (Command Prompt)
> Press [Windows] button
> Search “Command Prompt”
> Right-click> select “Run as administrator”
> Enter “java -version”
As a rule-of-thumb, it’s safer to select “Run as administrator” for ANY programs involved in an installation, if given the option. Often, installing without doing so may install that program at a lower permission level, and thus not everything may run seamlessly. Save yourself from countless hours of frustration and do yourself a favor: “Run as administrator” whenever possible. Just Do It.

This can also be done when not in administrator mode or in Terminal (otherwise known as Powershell). Just enter “java -version” and wait for the response. You should see something similar to the images above or below.

You can also check the version (if you already have it) by inspecting your installed applications.
> Press [Windows] button
> Settings (left-click)
> Apps (left-click)
> Installed apps (left-click)
> Search apps= “java”
A list of all, if any, versions of Java that have been installed are displayed. You can have multiple versions installed with no conflicts. But if you have any doubt, feel free to backup your PC, then uninstall from here.

+ [3] Set Environment Variables
> Press [Windows] button
> Search “env” for “Edit the system environment variables” (left-click open)
> Click [Environment Variables] button
* Focus on the bottom section: System variables
> Variable= Path (click to highlight)
> Click [Edit] button
This is where the path to your {JDK#\bin} folder should be added. If you install and find this line, you may delete this default line: {C:\Program Files\Common Files\Oracle\Java\javapath}.
* Default line often appears if no path is designated

- Install JDK
* In order to know WHAT path to add, you’ll need to install your JDK
> Search in Windows Explorer folder: C:\Program Files\Java
> Identify the matching folder to your recently installed JDK
* Java 8: looks like folder jdk1.8.0_###
* Java 17: looks like folder jdk-17
* Java 19: looks like folder jdk-19

> Copy the path through the bin folder: “C:\Program Files\Java\jdk-19”
> Return back to the [Edit environment variable] window:
> Click [New] button
> Paste JDK path
*Optional: Click [Move Up] button to move line up or left-most string in the previous window.
> Click the next 3 [OK] buttons until all Environment Variable properties windows are closed. (system may not recognize update until all of them are closed)
> Do [2] Confirm JDK Version (Command Prompt)

[Section D] DOWNLOAD BROWSER, SELENIUM JARS, WEBDRIVER
+ [4] Confirm Chrome browser
* Browser: Settings/Help> About> Version
> In Chrome, look for a 3 dot pattern (ellipsis) in upper-right corner of menu bar
> Settings/Help
> About Google Chrome/About Chrome
> Version #(#bit) information

+ [5] Confirm Selenium (latest)
> Get Selenium driver (JARs) from https://www.selenium.dev/downloads/
* Of the 5 main driver types (C#, Ruby, Java, Python, & JavaScript), we’ll be scrolling down to use Java version: Selenium 4.8.1
(https://github.com/SeleniumHQ/selenium/releases/download/selenium-4.8.0/selenium-java-4.8.1.zip)

+ [6] Confirm matching driver for browser/OS
*Recommend unzip driver & move only driver executable to C:\
> Get Chrome (ChromeDriver)= https://chromedriver.chromium.org/

[Section E] CREATE ECLIPSE PROJECT, PACKAGE, CLASS, INSTALL JARS
+ [7] Set up Eclipse IDE (latest)
The great thing about installing Eclipse is you can simultaneously have multiple versions. Unfortunately, if a shortcut is made, it corresponds ONLY to that version. Be mindful where you install your folders/shortcuts and you shouldn’t run into any problems. Before downloading, simply designate a separate folder on your Desktop or create a [C:\dev\eclipse#] folder for each version.
> Search in browser for “download eclipse jee 2022” or go directly to: https://www.eclipse.org/downloads/packages/ for Eclipse IDE 2022–12 R Packages: Eclipse IDE for Enterprise Java and Web Developers

> Click link for: Windows x86_64
https://www.eclipse.org/downloads/packages/release/2022-12/r/eclipse-ide-enterprise-java-and-web-developers
> Extract to designated folder

> In this same folder, create another folder to be used for the workspace (name can include spaces, #s)
> Navigate into extracted eclipse folder (Menu bar> View> Show> checkmark File name extensions)
> Find eclipse.exe (purple ball icon)
> Right-click “Run as administrator”
> Confirm [Yes] button
* A pop-up window will display to designate the workspace folder
> Click [Browse…] button to navigate to your new workspace folder
> Click folder & [Select Folder] button
> Click [Launch] button

* Eclipse window will disappear, then open full IDE window
> Click “X” to close Welcome screen

- Dark Mode
If you’re like me, Dark Mode is the way to go.
> On Menu bar:
> Click Window
> Click Preferences
> Click Appearance
> Theme: Dark
> Click [Apply & Close]
> Click [Restart]

- Create a new project, package, and class
On Menu bar:
> Click File
> Click New
> Click Other…
> Select “Java Project”
> Click [Next] button

> Project name: type desired project name, starting with a lowercase letter (*see blue warning at top of image)
> At bottom section Module, uncheck box: Create module-info.java file
> Click [Finish] button
> Click [Open Perspective] button *optional to click “Remember my decision”
> Expand project until {src} folder is displayed
> Right-click {src} folder> New> Package (also starting with a lowercase letter)> click [Finish] button

> Right-click {package} folder> New> Class (name starting with capital letter) & checkmark method stub: public static void main(String[] args)> click [Finish] button
*Update name of project/package/class/etc., right-click object> Refactor> Rename> click [OK] button

- Install Selenium Driver JARs
> Right-click project folder
> Click Properties
> Select “Java Build Path”
> Click “Libraries”
> Click “Classpath”
* Notice [Add External JARs…] button is now enabled
> Click [Add External JARs…] button
> Navigate to folder containing {C:\Users\user\Desktop\…\Selenium Downloads\selenium-java-4.8.1\lib} & select all [Ctrl+A]
> Click [Open] button
> Click [Apply] button
> Click “Classpath” again
* Notice [Add External JARs…] button is now enabled
> Click [Add External JARs…] button
> Navigate to folder containing {C:\Users\user\Desktop\…\Selenium Downloads\selenium-java-4.8.1} & select all [Ctrl+A], but deselect lib folder
> Click [Open] button
> Click [Apply] button
> Click [Apply and Close] button

[Section F] CODE TO LAUNCH AUTOMATED BROWSER
See how line 11 has a red X? Originally, the red X was under both WebDriver & ChromeDriver. By hovering over each string, a tooltip box appeared with suggestions. The top blue tip was to “Import” line 3 (before it was added) for WebDriver. Another line needs to be imported for ChromeDriver() as “Import org.openqa.selenium.chrome.ChromeDriver;”
> Be sure to click Import… for both WebDriver & ChromeDriver
> From Menu bar, click Run> Run As> 1 Java Application (automatically saves)
* The 1st time Eclipse tries to run, a pop-up should appear regarding Firewall permissions; click [Allow access] on Firewall prompt
> Witness an automated Chrome browser appear, then disappear
> Console tab then prints “Test Successful”

[Section G] TROUBLESHOOTING TIPS
+ If it does not work for you, try these tips:
- Check the easy stuff: double check code capitalization/lowercase strings match
- Check path to driver is correctly using double \\ between folders
- Missing JARS: reapply
- Incompatible browser/driver: verify correct match; may need to downgrade browser/driver version
* https://helpdeskgeek.com/how-to/how-to-downgrade-google-chrome-to-an-older-version/
- Search for more help online

We did cover the other browser/driver versions, but the instructor confirmed some of the versions were not compatible at this time. Fortunately, we were given a few days before our environments needed to be set up. The class videos were conveniently available minutes after class ended (always followed by a survey). By rewatching in different speeds from 0.5x to 2x, I was able to easily reassess many steps that were somewhat unclear during the class. The course is based in India & sometimes the accents take a moment to decipher. Don’t get me wrong; I LOVE hearing various accents. But others may find that aspect challenging.

--

--