> For the complete documentation index, see [llms.txt](https://developers.oxylabs.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.oxylabs.io/integrations/proxy-integrations/selenium.md).

# Selenium

[**Selenium**](https://www.selenium.dev/) is a tool that helps automate web browser interactions for website testing and more.

Watch our video guide or follow the steps below to integrate Selenium [**Python**](#python-setup) or [**Java**](#how-to-integrate-proxies-with-selenium-using-java) with the following Oxylabs proxies:

* **Residential & Mobile Proxies**
* **Datacenter Proxies**
* **Dedicated Datacenter Proxies (Enterprise)**
* **Dedicated Datacenter Proxies (Self-service)**
* **ISP Proxies**
* **Dedicated ISP Proxies**

{% embed url="<https://www.youtube.com/watch?v=uh71blwf1l0>" %}

## **Python setup**

{% stepper %}
{% step %}

### Setting up Selenium

Since using the default Selenium module for implementing proxies that require authentication makes the whole process complicated, install [**Selenium Wire**](https://github.com/wkeeling/selenium-wire) to extend Selenium's Python bindings using `pip`:

```
pip install selenium-wire
```

Another recommended package for this integration is `webdriver-manager`. It's a package that simplifies the management of binary drivers for different browsers:

```
pip install webdriver-manager
```

{% endstep %}

{% step %}

### Proxy authentication

Specify your chosen proxy endpoint and account credentials in the following format:

```python
USERNAME = "your_username"
PASSWORD = "your_password"
ENDPOINT = "host:port"
```

Then adjust their values according to your chosen Oxylabs proxy type:

* [Residential & Mobile Proxies](#residential-and-mobile-proxies)
* [Datacenter Proxies](#datacenter-proxies)
* [Dedicated Datacenter Proxies (Enterprise)](#dedicated-datacenter-proxies-enterprise)
* [Dedicated Datacenter Proxies (Self-service)](#dedicated-datacenter-proxies-self-service)
* [ISP Proxies](#isp-proxies)
* [Dedicated ISP Proxies](#dedicated-isp-proxies)

#### Residential & Mobile Proxies

**Host:** `pr.oxylabs.io`

**Port:** `7777`

**Username:** `customer-USERNAME`

**Password:** `PASSWORD`

{% hint style="warning" %}
**Note:** Don't forget to add `customer-` prefix to your username.
{% endhint %}

You may also use additional parameters with residential and mobile proxies to set the geo-location (country, state, city, and etc.) and control sessions. Check out the [Residential Proxies documentation](/products/proxies/residential-proxies.md) to learn more.

#### Datacenter Proxies

**Host:** `dc.oxylabs.io`

**Port:** `8001`

**Username:** `user-username`

**Password:** `password`

{% hint style="warning" %}
**Note:** Don't forget to add `user-` prefix to your username.
{% endhint %}

{% tabs %}
{% tab title="Pay-per-IP subscription" %}
The port is the sequential number assigned to an IP address from the [proxy list](/products/proxies/datacenter-proxies/proxy-list.md). Thus, port `8001` uses the first IP address from your list. You may also enable [proxy IP rotation](/products/proxies/datacenter-proxies/ip-control.md) by setting the port to `8000`.

Furthermore, you can specify the [geo-location](/products/proxies/datacenter-proxies/select-country.md), for example, the US, by setting the **Proxy username** to `user-USERNAME-country-US`.
{% endtab %}

{% tab title="Pay-per-traffic subscription" %}
The port `8001` picks a random IP address but stays consistent during a session. Alternatively, you can [rotate proxy IPs](/products/proxies/datacenter-proxies/ip-control.md) with each request by using port `8000`.

If you want to use a specific [geo-location](/products/proxies/datacenter-proxies/select-country.md), for example, the US, set the Proxy username to `user-USERNAME-country-US`.
{% endtab %}
{% endtabs %}

#### Dedicated Datacenter Proxies (Enterprise)

**Host:** `1.2.3.4` (IP address from your [proxy list](/products/proxies/dedicated-datacenter-proxies/enterprise/proxy-lists.md))

**Port:** `60000` (HTTP), `1180` (SOCKS5)

**Username:** `username`

**Password:** `password`

For Enterprise Dedicated Datacenter Proxies (purchased through sales team), you’ll have to choose an IP address from the acquired [proxy list](/products/proxies/dedicated-datacenter-proxies/enterprise/proxy-lists.md).

#### Dedicated Datacenter Proxies (Self-service)

**Host:** `ddc.oxylabs.io`

**Port:** `8001`

**Username:** `user-username`

**Password:** `password`

{% hint style="warning" %}
**Note:** Don't forget to add `user-` prefix to your username.
{% endhint %}

For Self-Service Dedicated Datacenter Proxies (purchased through Oxylabs dashboard), the port indicates the sequential number of an IP address from the acquired [proxy list](/products/proxies/dedicated-datacenter-proxies/self-service/proxy-list.md). If you want to get a different IP with each request, change the Port to `8000` to enable [proxy rotation](/products/proxies/dedicated-datacenter-proxies/self-service/proxy-rotation.md).

#### ISP Proxies

**Host:** `isp.oxylabs.io`

**Port:** `8001`

**Username:** `user-username`

**Password:** `password`

{% hint style="warning" %}
**Note:** Don't forget to add `user-` prefix to your username.
{% endhint %}

With ISP Proxies, the port is assigned to a specific IP address and its location. Hence, port `8001` will always pick the first IP from your [proxy list](/products/proxies/isp-proxies/proxy-list.md). If you want to get a different IP with each request, change the Port to `8000` to enable [proxy rotation](/products/proxies/isp-proxies/proxy-rotation.md).

#### Dedicated ISP Proxies

**Host:** `disp.oxylabs.io`

**Port:** `8001`

**Username:** `user-username`

**Password:** `password`

{% hint style="warning" %}
**Note:** Don't forget to add `user-` prefix to your username.
{% endhint %}

You will need to choose the port assigned to an IP address from the purchased [proxy list](/products/proxies/dedicated-isp-proxies/self-service/proxy-list.md), which you can find on the Oxylabs dashboard. The `8001` port will pick the first IP address from your list for all requests. Use port `8000` for automatic [proxy IP rotation](/products/proxies/dedicated-isp-proxies/self-service/proxy-rotation.md).
{% endstep %}

{% step %}

### Testing the connection

Check if the proxy is working by visiting [**ip.oxylabs.io**](https://ip.oxylabs.io/). If everything is working correctly - it will return an IP address of a proxy you're using.

```python
try:
    driver.get("https://ip.oxylabs.io/")
    return f'\nYour IP is: {driver.find_element(By.CSS_SELECTOR, "pre").text}'
finally:
    driver.quit()
```

{% endstep %}

{% step %}

### Code sample

Complete code for Oxylabs Residential Proxies integration with Selenium:

```python
from selenium.webdriver.common.by import By
from seleniumwire import webdriver
# A package to have a chromedriver always up-to-date.
from webdriver_manager.chrome import ChromeDriverManager

USERNAME = "your_username"
PASSWORD = "your_password"
ENDPOINT = "pr.oxylabs.io:7777"

def chrome_proxy(user: str, password: str, endpoint: str) -> dict:
    wire_options = {
        "proxy": {
            "http": f"http://{user}:{password}@{endpoint}",
            "https": f"https://{user}:{password}@{endpoint}",
        }
    }

    return wire_options

def execute_driver():
    options = webdriver.ChromeOptions()
    options.add_argument('--headless')
    proxies = chrome_proxy(USERNAME, PASSWORD, ENDPOINT)
    driver = webdriver.Chrome(
    ChromeDriverManager(driver_version='<VERSION>').install(), options=options, seleniumwire_options=proxies
    )
    try:
        driver.get("https://ip.oxylabs.io/")
        return f'\nYour IP is: {driver.find_element(By.CSS_SELECTOR, "pre").text}'
    finally:
        driver.quit()


if __name__ == '__main__':
    print(execute_driver())
```

{% endstep %}
{% endstepper %}

## Java setup <a href="#how-to-integrate-proxies-with-selenium-using-java" id="how-to-integrate-proxies-with-selenium-using-java"></a>

### Prerequisites

1. **Java Development Kit (JDK):** Version 8 or higher (find newest version [here](https://www.oracle.com/java/technologies/downloads/)).
2. **Build Tool:** Apache Maven (available [here](https://www.oracle.com/java/technologies/downloads/)).
3. **Java IDE:** Any IDE or CLI supporting Maven.
4. **Browser:** Google Chrome installed locally (available [here](https://www.google.com/chrome)).

Initialize a standard Maven project in your preferred IDE or CLI before adding dependencies. After installing, you can verify your Java and Maven installations using the following lines:

```
java -version
```

<img src="https://oxylabs.io/oxylabs-web/ZpA8dR5LeNNTxDst_4b72a4dd-3675-4391-b18d-bc2a85414588_java_version.png?auto=format%2Ccompress&#x26;w=3840&#x26;q=75" alt="" height="120" width="681">

```
mvn -v
```

<img src="https://oxylabs.io/oxylabs-web/ZpA8dh5LeNNTxDsu_94c7e32d-acd6-439c-8d60-f047c4de6195_maven_version.png?auto=format%2Ccompress&#x26;w=3840&#x26;q=75" alt="" height="123" width="763">

{% stepper %}
{% step %}

### Create your project

Select “New Project”, fill in the required details, and select the build system as Maven:

<img src="https://oxylabs.io/oxylabs-web/ZpA8dx5LeNNTxDsv_27754abb-a0c9-40af-ad7a-e82de9505fe6_maven1.png?auto=format%2Ccompress&#x26;w=3840&#x26;q=75" alt="" height="705" width="784">
{% endstep %}

{% step %}

### Add dependencies

Add the following dependencies to your project's `pom.xml` file to include Selenium WebDriver, [BrowserMob Proxy](https://github.com/lightbody/browsermob-proxy) (for HTTP basic authentication), and [WebDriverManager](https://github.com/bonigarcia/webdrivermanager):

```xml
<dependencies>
   <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
   <dependency>
       <groupId>org.seleniumhq.selenium</groupId>
       <artifactId>selenium-java</artifactId>
       <version>4.11.0</version>
   </dependency>
   <!-- https://mvnrepository.com/artifact/net.lightbody.bmp/browsermob-core -->
   <dependency>
       <groupId>net.lightbody.bmp</groupId>
       <artifactId>browsermob-core</artifactId>
       <version>2.1.5</version>
   </dependency>
   <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-simple</artifactId>
       <version>1.7.32</version>
   </dependency>
   <!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
   <dependency>
       <groupId>io.github.bonigarcia</groupId>
       <artifactId>webdrivermanager</artifactId>
       <version>5.5.2</version>
   </dependency>
   <!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
   <dependency>
       <groupId>com.google.guava</groupId>
       <artifactId>guava</artifactId>
       <version>32.1.2-jre</version>
   </dependency>

</dependencies>
```

{% endstep %}

{% step %}

### Add source code

Download the pre-configured proxy wrapper classes from the [Oxylabs Selenium Java Repository](https://github.com/oxylabs/selenium-proxy-integration-java/tree/main/src/main/java) and add them to your project's `src/main/java` directory:

* `ProxySetup.java`: Stores your proxy endpoint parameters and account credentials.
* `ProxyHelper.java`: Manages `BrowserMobProxyServer` initialization, basic authentication, and `ChromeDriver` options.
* `ProxyDemo.java`: Contains sample execution logic for standard and country-targeted proxy requests.
  {% endstep %}

{% step %}

### Configure proxies

Open `ProxySetup.java` and update the proxy details according to your chosen Oxylabs proxy type:

* [Residential & Mobile Proxies](#residential-and-mobile-proxies-1)
* [Datacenter Proxies](#datacenter-proxies-1)
* [Dedicated Datacenter Proxies (Enterprise)](#dedicated-datacenter-proxies-enterprise-1)
* [Dedicated Datacenter Proxies (Self-service)](#dedicated-datacenter-proxies-self-service-1)
* [ISP Proxies](#isp-proxies-1)
* [Dedicated ISP Proxies](#dedicated-isp-proxies-1)

#### Residential & Mobile Proxies

```java
final class ProxySetup {
    static final String ENDPOINT = "pr.oxylabs.io:7777"; //host:port
    static final String USERNAME = "customer-USERNAME";
    static final String PASSWORD = "PASSWORD";
}
```

**Host:** `pr.oxylabs.io`

**Port:** `7777`

**Username:** `customer-USERNAME`

**Password:** `PASSWORD`

{% hint style="warning" %}
**Note:** Don't forget to add `customer-` prefix to your username.
{% endhint %}

You may also use additional parameters with residential and mobile proxies to set the geo-location (country, state, city, and etc.) and control sessions. Check out the [Residential Proxies documentation](/products/proxies/residential-proxies.md) to learn more.

#### Datacenter Proxies

```java
final class ProxySetup {
    static final String ENDPOINT = "dc.oxylabs.io:8001"; //host:port
    static final String USERNAME = "user-USERNAME";
    static final String PASSWORD = "PASSWORD";
}
```

**Host:** `dc.oxylabs.io`

**Port:** `8001`

**Username:** `user-USERNAME`

**Password:** `PASSWORD`

{% hint style="warning" %}
**Note:** Don't forget to add `user-` prefix to your username.
{% endhint %}

{% tabs %}
{% tab title="Pay-per-IP subscription" %}
The port is the sequential number assigned to an IP address from the [proxy list](/products/proxies/datacenter-proxies/proxy-list.md). Thus, port `8001` uses the first IP address from your list. You may also enable [proxy IP rotation](/products/proxies/datacenter-proxies/ip-control.md) by setting the port to `8000`.

Furthermore, you can specify the [geo-location](/products/proxies/datacenter-proxies/select-country.md), for example, the US, by setting the **Proxy username** to `user-USERNAME-country-US`.
{% endtab %}

{% tab title="Pay-per-traffic subscription" %}
The port `8001` picks a random IP address but stays consistent during a session. Alternatively, you can [rotate proxy IPs](/products/proxies/datacenter-proxies/ip-control.md) with each request by using port `8000`.

If you want to use a specific [geo-location](/products/proxies/datacenter-proxies/select-country.md), for example, the US, set the Proxy username to `user-USERNAME-country-US`.
{% endtab %}
{% endtabs %}

#### Dedicated Datacenter Proxies (Enterprise)

```java
final class ProxySetup {
    static final String ENDPOINT = "1.2.3.4:60000"; //host:port
    static final String USERNAME = "USERNAME";
    static final String PASSWORD = "PASSWORD";
}
```

**Host:** `1.2.3.4` (IP address from your [proxy list](/products/proxies/dedicated-datacenter-proxies/enterprise/proxy-lists.md))

**Port:** `60000` (HTTP), `1180` (SOCKS5)

**Username:** `USERNAME`

**Password:** `PASSWORD`

For Enterprise Dedicated Datacenter Proxies (purchased through sales team), you’ll have to choose an IP address from the acquired [proxy list](/products/proxies/dedicated-datacenter-proxies/enterprise/proxy-lists.md).

#### Dedicated Datacenter Proxies (Self-service)

```java
final class ProxySetup {
    static final String ENDPOINT = "ddc.oxylabs.io:8001"; //host:port
    static final String USERNAME = "user-USERNAME";
    static final String PASSWORD = "PASSWORD";
}
```

**Host:** `ddc.oxylabs.io`

**Port:** `8001`

**Username:** `user-USERNAME`

**Password:** `PASSWORD`

{% hint style="warning" %}
**Note:** Don't forget to add `user-` prefix to your username.
{% endhint %}

For Self-Service Dedicated Datacenter Proxies (purchased through Oxylabs dashboard), the port indicates the sequential number of an IP address from the acquired [proxy list](/products/proxies/dedicated-datacenter-proxies/self-service/proxy-list.md). If you want to get a different IP with each request, change the Port to `8000` to enable [proxy rotation](/products/proxies/dedicated-datacenter-proxies/self-service/proxy-rotation.md).

#### ISP Proxies

```java
final class ProxySetup {
    static final String ENDPOINT = "isp.oxylabs.io:8001"; //host:port
    static final String USERNAME = "user-USERNAME";
    static final String PASSWORD = "PASSWORD";
}
```

**Host:** `isp.oxylabs.io`

**Port:** `8001`

**Username:** `user-USERNAME`

**Password:** `PASSWORD`

{% hint style="warning" %}
**Note:** Don't forget to add `user-` prefix to your username.
{% endhint %}

With ISP Proxies, the port is assigned to a specific IP address and its location. Hence, port `8001` will always pick the first IP from your [proxy list](/products/proxies/isp-proxies/proxy-list.md). If you want to get a different IP with each request, change the Port to `8000` to enable [proxy rotation](/products/proxies/isp-proxies/proxy-rotation.md).

#### Dedicated ISP Proxies

```java
final class ProxySetup {
    static final String ENDPOINT = "disp.oxylabs.io:8001"; //host:port
    static final String USERNAME = "user-USERNAME";
    static final String PASSWORD = "PASSWORD";
}
```

**Host:** `disp.oxylabs.io`

**Port:** `8001`

**Username:** `user-USERNAME`

**Password:** `PASSWORD`

{% hint style="warning" %}
**Note:** Don't forget to add `user-` prefix to your username.
{% endhint %}

You will need to choose the port assigned to an IP address from the purchased [proxy list](/products/proxies/dedicated-isp-proxies/self-service/proxy-list.md), which you can find on the Oxylabs dashboard. The `8001` port will pick the first IP address from your list for all requests. Use port `8000` for automatic [proxy IP rotation](/products/proxies/dedicated-isp-proxies/self-service/proxy-rotation.md).
{% endstep %}

{% step %}

### Execute the integration script

Execute `ProxyDemo.java` directly within your IDE, or compile and run the packaged JAR file using Maven via the terminal:

```
mvn clean package
java -cp target/oxylabs-selenium-jar-with-dependencies.jar ProxyDemo
```

Upon execution, `ProxyDemo` initializes the driver, routes traffic through the specified Oxylabs endpoint via BrowserMob, and prints the resolved exit IP address.

However, you may need to install proper certificates to enable SSL support and avoid certificate-related warnings covered in the next step.
{% endstep %}

{% step %}

### SSL Certificate Handling (optional)

The code uses BrowserMob Proxy, which supports full MITM. However, you may still see invalid certificate warnings.

#### Programmatic Bypass (Recommended)

Pass `--ignore-certificate-errors` via `ChromeOptions` in `ProxyHelper.java` to bypass SSL validation during automated execution.

#### Root Certificate Installation

Import the BrowserMob root certificate ([ca-certificate-rsa.cer](https://github.com/oxylabs/selenium-proxy-integration-java/blob/main/certificates/ca-certificate-rsa.cer)) into your operating system's trust store

* **macOS:** Drag `ca-certificate-rsa.cer` into *Keychain Access* > *System* > *Certificates*, right-click, and select *Always Trust*.
* **Windows:** Double-click `ca-certificate-rsa.cer`, select *Install Certificate*, and set the import destination to *Trusted Root Certification Authorities*.
  {% endstep %}
  {% endstepper %}

If you want to learn more about web scraping with Selenium, read our [**blog post**](https://oxylabs.io/blog/selenium-web-scraping).

Find the original Selenium integration blog post [here](https://oxylabs.io/resources/integrations/selenium).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://developers.oxylabs.io/integrations/proxy-integrations/selenium.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
