Setting Up Automation Script with Selenium and Chrome CLI
This guide provides step-by-step instructions to set up an automation script using Python with Selenium and Google Chrome on a Linux environment.Step 1: Install Google Chrome
-
Download the Google Chrome .deb package:
-
Install the package:
Step 2: Download ChromeDriver
-
Determine the version of Chrome you have installed:
Note the version number (e.g.,
114.0.5735.90). -
Download the matching version of ChromeDriver from the ChromeDriver download page:
Step 3: Move ChromeDriver to a Directory in Your PATH
-
Move the
chromedriverbinary to/usr/local/bin: -
Verify the installation:
Using ChromeDriver with Selenium
-
Install Selenium:
-
Verify your installations:
Steps to Resolve Common Issues
Verify the ChromeDriver File Location
-
Ensure you are pointing to the correct
chromedriverbinary: -
Ensure the binary is named
chromedriverand has executable permissions:
Update Your Script to Use the Correct Path
Ensure your script is pointing to the correctchromedriver path. Using webdriver.Chrome() with ChromeDriverManager should automatically handle this. Ensure you are using the latest version:
Clear ChromeDriver Cache and Reinstall
-
Remove old ChromeDriver files:
-
Install ChromeDriver again using
webdriver_manager.
Creating a Google Chrome Profile on Ubuntu for Selenium
Step 1: Create a New Chrome Profile
-
Launch Google Chrome and access profile management:
- Click on your profile icon in the upper right corner of the Chrome window and select “Add” to create a new profile.
- Choose a name and avatar for the profile and click “Add”.
-
Locate Profile Directory:
Step 2: Configure Selenium to Use the Chrome Profile
-
Create a new directory for the profile:
-
Launch Chrome with the new profile:
-
Close Chrome. The profile is now created and saved in
~/.config/google-chrome/NewProfile.
Using Xvfb for a Virtual Framebuffer
If you need a graphical environment but don’t have an actual display, use Xvfb (X virtual framebuffer) to emulate a display.-
Install Xvfb:
-
Run Xvfb in the background:
-
Set the DISPLAY environment variable:
-
Launch Chrome with the new profile:
-
Run Selenium with the DISPLAY variable:
Verifying File Permissions
- Verify the
chromedriverfile:
By following these steps, you should be able to set up your automation script with Selenium and Chrome, resolving any issues related to chromedriver installation and configuration.
https://chatgpt.com/share/d66b9e03-b408-43e6-a827-0955f55ee1ee
