# Selenium

#### What is Selenium?

[**Selenium**](https://www.selenium.dev/) is an umbrella project for a range of tools and libraries that enable and support the automation of web browsers.

Selenium is many things but at its core, it is a toolset for web browser automation that uses the best techniques available to remotely control browser instances and emulate a user’s interaction with the browser.

<figure><img src="https://340306199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1wQhlaRQzrtcn9wgMUU5%2Fuploads%2FxTcaNQJ3rzwyXgCU4Vii%2Fimage.png?alt=media&#x26;token=93d84062-24d6-4891-bba3-300a17ac9972" alt=""><figcaption></figcaption></figure>

Here's how to integrate Thordata with Selenium.

{% stepper %}
{% step %}

### Install Selenium

Install [**Selenium Wire**](https://github.com/wkeeling/selenium-wire) to extend Selenium's Python bindings because using the default Selenium module for implementing proxies that require authentication makes the whole process complicated. You can do it using the `pip` command: `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. In this case, **there's no need to manually download a new version of a web driver after each update**.

You can install the `webdriver-manager` using the `pip` command as well: `pip install webdriver-manager`
{% endstep %}

{% step %}

### Specify your user credentials for proxies to work

`USERNAME = "td-customer-USERNAME"`

`PASSWORD = "PASSWORD"`

`ENDPOINT = "t.pr.thordata.net:9999"`
{% endstep %}

{% step %}

### Check proxy status

Check if the proxy is working by visiting `ipinfo.thordata.com`. If everything is working correctly - it will return an IP address of a proxy you're using.

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

{% endstep %}
{% endstepper %}

**Full Code Example:**

```
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 = "td-customer-USERNAME"
PASSWORD = "PASSWORD"
ENDPOINT = "t.pr.thordata.net:9999"

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://ipinfo.thordata.com/")
        return f'\nYour IP is: {driver.find_element(By.CSS_SELECTOR, "pre").text}'
    finally:
        driver.quit()


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