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

# Selenium

> Set up Selenium with Python using NodeMaven proxies and IP whitelisting.

Selenium is an open-source tool for automating web browsers. Selenium supports multiple programming languages, including Python, Java, and C#, and is widely used for web testing, scraping, and automating repetitive tasks. Selenium works across browsers like Chrome, Firefox, and Edge, and offers robust features for interacting with web elements.

For more information, visit [The Selenium Browser Automation Project](https://www.selenium.dev/documentation/).

## Check whether Python is installed

Before anything, check whether Python is installed. Open a terminal (Command Prompt or shell) and run:

```bash theme={null}
python --version
```

If Python is installed, this displays the version number:

<Frame>
  <img src="https://downloads.intercomcdn.com/i/o/yvkc0rpk/1264051203/26d26453c9e050964eb7e08cb1cc/S1.png" alt="Terminal showing the installed Python version number" />
</Frame>

If Python is already installed, skip ahead to Step 2 and install Selenium.

## Step 1: Install Python

<Steps>
  <Step title="Download Python">
    Download Python from the [official Python downloads page](https://www.python.org/downloads/).

    <Frame>
      <img src="https://downloads.intercomcdn.com/i/o/yvkc0rpk/1264054747/ce55a12b6a9d7b9d23df8b59a845/S2.png" alt="Python downloads page" />
    </Frame>
  </Step>

  <Step title="Run the installer">
    Run the installer and make sure to check the option **Add Python to PATH** during installation.
  </Step>
</Steps>

## Step 2: Install Selenium and WebDriver

<Steps>
  <Step title="Install Selenium">
    ```bash theme={null}
    pip install selenium
    ```
  </Step>

  <Step title="Install WebDriver">
    ```bash theme={null}
    pip install webdriver-manager
    ```
  </Step>
</Steps>

## Step 3: Create a project directory

Create the project directory:

```bash theme={null}
mkdir selenium_project
```

Navigate to the newly created directory and create a subdirectory for scripts:

```bash theme={null}
cd selenium_project
mkdir src
```

## Step 4: Write your Selenium script

Open a text editor and paste the following script:

```python theme={null}
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options

# Configure proxy with IP whitelisting
proxy = "http://gate.nodemaven.com:8080"  # Replace with your proxy string

# Set Chrome options to use the proxy
chrome_options = Options()
chrome_options.add_argument(f"--proxy-server={proxy}")

# Initialize WebDriver
driver = webdriver.Chrome(
    service=Service(ChromeDriverManager().install()),
    options=chrome_options
)

try:
    # Navigate to an IP-checking service
    driver.get("https://www.maxmind.com/en/locate-my-ip-address")
    print("Page title:", driver.title)

    # Extract the IP address from the page (if displayed)
    page_source = driver.page_source
    print("Page content loaded. Check the browser to verify the proxy works.")
except Exception as e:
    print("An error occurred:", e)
finally:
    # Close the browser
    driver.quit()
```

Save the file as `selenium_test.py` inside the `src` directory. The script above uses [IP whitelisting](/residential-mobile/ip-whitelist), so replace the proxy string with your own.

## Step 5: Run your script

Open Command Prompt, navigate to the `src` directory, and run:

```bash theme={null}
python selenium_test.py
```

### Expected output

The browser opens, navigates to `https://www.maxmind.com/en/locate-my-ip-address`, and displays your IP address and related details.

<Frame>
  <img src="https://downloads.intercomcdn.com/i/o/yvkc0rpk/1264772980/b0cdddfd96a84fda47167ccea6cc/S3.png" alt="MaxMind page opened by Selenium showing the proxy IP address" />
</Frame>

The Command Prompt prints the page title:

<Frame>
  <img src="https://downloads.intercomcdn.com/i/o/yvkc0rpk/1264774643/cf65ee4f6fb237d935f4bfaa6ea6/S4.png" alt="Command Prompt showing the page title printed by the Selenium script" />
</Frame>

You are now ready to personalize your script and start using Selenium with NodeMaven proxies.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.