# Selenium

Selenium is a tool that helps automate web browser interactions for website testing and more.

To integrate Selenium with GoProxies, you would need to follow the steps below:

* Firstly, you would need to install [**Selenium Wire**](https://github.com/wkeeling/selenium-wire) to extend Selenium's Python bindings, since using the default Selenium module for implementing proxies that require authentication makes it complicated.
* Another package which is recommended for this integration is webdriver-manager. It's a package that simplifies the management of binary drivers for different browsers. In this case, there's no need to manually download a new version of a web driver after each update.

You can install both packages using the following command:

```bash
pip install selenium selenium-wire webdriver-manager
```

{% hint style="info" %}
Note: if using Python 3.13 and you encounter a `blinker._saferef` error, install:

```bash
pip install blinker==1.6.2
```

{% endhint %}

* Specify your account credentials for proxies to work:
  * Firstly, you would need to replace 'your\_username' and 'your\_password' with your credentials.
  * Then you need to specify the endpoint, in this example we're using '`proxy.goproxies.com:1080`'
* The full example of a code should look like this:

```python
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from seleniumwire import webdriver
from webdriver_manager.chrome import ChromeDriverManager

# =========================
# Replace with your details
# =========================
USERNAME = "customer-your_username"
PASSWORD = "your_password"
ENDPOINT = "proxy.goproxies.com:1080"
# =========================


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


def create_driver():
    chrome_options = webdriver.ChromeOptions()

    # Visible browser is recommended for testing
    # Uncomment the line below if you want headless mode
    # chrome_options.add_argument("--headless=new")

    chrome_options.add_argument("--window-size=1920,1080")
    chrome_options.add_argument("--no-sandbox")
    chrome_options.add_argument("--disable-dev-shm-usage")

    # Optional: reduce page load hanging on heavy JS sites
    chrome_options.page_load_strategy = "eager"

    service = Service(ChromeDriverManager().install())

    driver = webdriver.Chrome(
        service=service,
        options=chrome_options,
        seleniumwire_options=get_proxy_options(USERNAME, PASSWORD, ENDPOINT),
    )

    return driver


def test_proxy():
    driver = create_driver()

    try:
        driver.get("https://ip.goproxies.com/")
        ip = driver.find_element(By.TAG_NAME, "body").text.strip()
        print(f"Your IP is: {ip}")

    finally:
        driver.quit()


if __name__ == "__main__":
    test_proxy()
```

That's it! You've set-up GoProxies via Selenium.

Now run the script by entering the following into your command prompt where the python file is located:

```bash
python your_script_name.py
```

If configured correctly, the script will print the residential IP assigned by GoProxies.

{% hint style="info" %}

* This example uses an HTTP proxy endpoint (:1080)
* For SOCKS5 proxies, use port 10003 and change the scheme to socks5:// .
* Some websites apply advanced bot mitigation. In such cases, using a full browser automation framework (Selenium, Playwright) is recommended over direct HTTP libraries like python's `requests`.
  {% endhint %}


---

# Agent Instructions: 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:

```
GET https://docs.goproxies.com/proxies/integrations/browsers/selenium.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
