Skip to content

Selenium Integration

Selenium is a popular web automation testing framework that supports multiple programming languages.

Python Example

Installation

bash
pip install selenium

Basic Configuration

python
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy, ProxyType

# Configure proxy
proxy = Proxy()
proxy.proxy_type = ProxyType.MANUAL
proxy.http_proxy = 'proxy.okkproxy.com:8080'
proxy.ssl_proxy = 'proxy.okkproxy.com:8080'

# Set authentication (if required)
capabilities = webdriver.DesiredCapabilities.CHROME
proxy.add_to_capabilities(capabilities)

# Create driver
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(options=options, desired_capabilities=capabilities)

# Navigate
driver.get('https://example.com')

# Check IP
driver.get('https://ipinfo.io')
print(driver.page_source)

driver.quit()

With Authentication

python
from selenium import webdriver

# Proxy with authentication
proxy = 'username:[email protected]:8080'

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument(f'--proxy-server=http://{proxy}')

driver = webdriver.Chrome(options=chrome_options)
driver.get('https://example.com')
driver.quit()

Node.js Example

javascript
const {Builder, By, Key, until} = require('selenium-webdriver');
const proxy = require('selenium-webdriver/proxy');

(async function example() {
  let driver = await new Builder()
    .forBrowser('chrome')
    .setProxy(proxy.manual({
      http: 'proxy.okkproxy.com:8080',
      https: 'proxy.okkproxy.com:8080'
    }))
    .build();

  try {
    await driver.get('https://example.com');
    // Your code here
  } finally {
    await driver.quit();
  }
})();

Best Practices

  1. Use Headless Mode (for production)
python
options.add_argument('--headless')
  1. Set Timeouts
python
driver.set_page_load_timeout(30)
driver.implicitly_wait(10)
  1. Handle Exceptions
python
try:
    driver.get(url)
except TimeoutException:
    print("Page load timeout")

Support