> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ahmadraza.in/llms.txt
> Use this file to discover all available pages before exploring further.

# ChromeCLI

# 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

1. Download the Google Chrome .deb package:
   ```sh theme={null}
   wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
   ```

2. Install the package:
   ```sh theme={null}
   sudo dpkg -i google-chrome-stable_current_amd64.deb
   sudo apt-get install -f
   ```

## Step 2: Download ChromeDriver

1. Determine the version of Chrome you have installed:
   ```sh theme={null}
   google-chrome --version
   ```
   Note the version number (e.g., `114.0.5735.90`).

2. Download the matching version of ChromeDriver from the ChromeDriver download page:
   ```sh theme={null}
   wget https://chromedriver.storage.googleapis.com/114.0.5735.90/chromedriver_linux64.zip
   unzip chromedriver_linux64.zip
   ```

## Step 3: Move ChromeDriver to a Directory in Your PATH

1. Move the `chromedriver` binary to `/usr/local/bin`:
   ```sh theme={null}
   sudo mv chromedriver /usr/local/bin/
   sudo chmod +x /usr/local/bin/chromedriver
   ```

2. Verify the installation:
   ```sh theme={null}
   chromedriver --version
   ```

## Using ChromeDriver with Selenium

1. Install Selenium:
   ```sh theme={null}
   pip install selenium
   ```

2. Verify your installations:
   ```sh theme={null}
   chromedriver --version
   google-chrome --version
   ls -l /usr/local/bin/chromedriver
   ```

## Steps to Resolve Common Issues

### Verify the ChromeDriver File Location

1. Ensure you are pointing to the correct `chromedriver` binary:
   ```sh theme={null}
   ls -l /home/ubuntu/.wdm/drivers/chromedriver/linux64/127.0.6533.88/
   ```

2. Ensure the binary is named `chromedriver` and has executable permissions:
   ```sh theme={null}
   chmod +x /home/ubuntu/.wdm/drivers/chromedriver/linux64/127.0.6533.88/chromedriver
   ```

### Update Your Script to Use the Correct Path

Ensure your script is pointing to the correct `chromedriver` path. Using `webdriver.Chrome()` with `ChromeDriverManager` should automatically handle this. Ensure you are using the latest version:

```sh theme={null}
pip install --upgrade webdriver_manager
```

### Clear ChromeDriver Cache and Reinstall

1. Remove old ChromeDriver files:
   ```sh theme={null}
   rm -rf /home/ubuntu/.wdm/
   ```

2. Install ChromeDriver again using `webdriver_manager`.

## Creating a Google Chrome Profile on Ubuntu for Selenium

### Step 1: Create a New Chrome Profile

1. 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".

2. Locate Profile Directory:
   ```sh theme={null}
   ls ~/.config/google-chrome/
   ls ~/.config/google-chrome/ | grep 'Profile'
   ```

### Step 2: Configure Selenium to Use the Chrome Profile

1. Create a new directory for the profile:
   ```sh theme={null}
   mkdir -p ~/.config/google-chrome/NewProfile
   ```

2. Launch Chrome with the new profile:
   ```sh theme={null}
   google-chrome --user-data-dir=~/.config/google-chrome/NewProfile --profile-directory=Profile1
   ```

3. 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.

1. Install Xvfb:
   ```sh theme={null}
   sudo apt-get install xvfb
   ```

2. Run Xvfb in the background:
   ```sh theme={null}
   Xvfb :99 -screen 0 1024x768x24 &
   ```

3. Set the DISPLAY environment variable:
   ```sh theme={null}
   export DISPLAY=:99
   ```

4. Launch Chrome with the new profile:
   ```sh theme={null}
   google-chrome --user-data-dir=~/.config/google-chrome/pt-auto-profile --profile-directory=pt-auto-profile1
   ```

5. Run Selenium with the DISPLAY variable:
   ```sh theme={null}
   export DISPLAY=:99
   ```

### Verifying File Permissions

1. Verify the `chromedriver` file:
   ```sh theme={null}
   file /usr/local/bin/chromedriver
   sudo chmod +x /usr/local/bin/chromedriver
   ls -l /usr/local/bin/chromedriver
   ```

> 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](https://chatgpt.com/share/d66b9e03-b408-43e6-a827-0955f55ee1ee)
