Selenium Grid enables distributed browser testing across multiple machines and browsers. Integrate KnoxProxy at the Grid node or driver level to run parallel geo-distributed test suites, validate region-locked features, and test localization across dozens of countries simultaneously.
Launch the Grid hub that coordinates test distribution.
java -jar selenium-server-4.x.jar hubCreate a node configuration file that sets the proxy for browsers.
# node-proxy.toml
[node]
max-sessions = 4
[node:env]
HTTP_PROXY = "http://USER:PASS@gw.knoxproxy.com:7000"
HTTPS_PROXY = "http://USER:PASS@gw.knoxproxy.com:7000"Launch the Grid node using the proxy-configured TOML file.
java -jar selenium-server-4.x.jar node \
--config node-proxy.toml \
--hub http://localhost:4444Connect to the Grid and set proxy capabilities on the driver.
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy, ProxyType
proxy = Proxy()
proxy.proxy_type = ProxyType.MANUAL
proxy.http_proxy = "gw.knoxproxy.com:7000"
proxy.ssl_proxy = "gw.knoxproxy.com:7000"
options = webdriver.ChromeOptions()
options.proxy = proxy
driver = webdriver.Remote(
command_executor="http://localhost:4444",
options=options,
)Use Chrome arguments or environment variables for country-specific proxy routing.
options = webdriver.ChromeOptions()
options.add_argument("--proxy-server=http://gw.knoxproxy.com:7000")
# Set env: HTTP_PROXY=http://USER-country-kr:PASS@gw.knoxproxy.com:7000Run Selenium Grid in Docker with proxy environment variables injected.
# docker-compose.yml snippet
services:
chrome:
image: selenium/node-chrome:4
environment:
- SE_EVENT_BUS_HOST=hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
- HTTP_PROXY=http://USER:PASS@gw.knoxproxy.com:7000
- HTTPS_PROXY=http://USER:PASS@gw.knoxproxy.com:7000from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy, ProxyType
from selenium.webdriver.common.by import By
import os
# Set proxy auth via environment
os.environ["HTTP_PROXY"] = "http://USER:PASS@gw.knoxproxy.com:7000"
os.environ["HTTPS_PROXY"] = "http://USER:PASS@gw.knoxproxy.com:7000"
# Configure proxy capabilities
proxy = Proxy()
proxy.proxy_type = ProxyType.MANUAL
proxy.http_proxy = "gw.knoxproxy.com:7000"
proxy.ssl_proxy = "gw.knoxproxy.com:7000"
options = webdriver.ChromeOptions()
options.proxy = proxy
# Connect to Selenium Grid
driver = webdriver.Remote(
command_executor="http://localhost:4444",
options=options,
)
try:
driver.get("https://httpbin.org/ip")
body = driver.find_element(By.TAG_NAME, "pre")
print(f"Exit IP: {body.text}")
driver.get("https://example.com")
assert driver.title != ""
print(f"Page title: {driver.title}")
finally:
driver.quit()Each Grid session creates a new browser and proxy connection. For country-specific nodes, run multiple Grid nodes with different HTTP_PROXY usernames (USER-country-us, USER-country-de). Use USER-session-{id} for sticky IPs within a session.
| Problem | Fix |
|---|---|
| SessionNotCreatedException: Could not start a new session | Verify HTTP_PROXY env var is set on the Grid node. Test with curl from the node machine. |
| WebDriverException: unknown error: net::ERR_PROXY_CONNECTION_FAILED | Check proxy format in capabilities. For Chrome, use --proxy-server arg. For Firefox, use the proxy capability object. |
| Timeout waiting for Grid node | Check Grid hub logs. Ensure node TOML config is valid. Reduce max-sessions if proxy bandwidth is limited. |
USER-country-de-city-berlin-session-profile07Order matters -- geo flags before the session flag. The session name is free text; use the profile ID so the mapping is self-documenting. Password stays as issued; no flags belong there. HTTP on :7000, SOCKS5 on :7001, same credentials.
Configure at the node level (via env vars or TOML) for a uniform proxy across all sessions. Use driver-level proxy capabilities when you need per-test country targeting.
Yes. Deploy Grid nodes with different HTTP_PROXY country usernames. Use node labels to route tests to specific country nodes.
Yes. Inject HTTP_PROXY and HTTPS_PROXY as environment variables in the docker-compose.yml or Kubernetes pod spec.
Set credentials in the HTTP_PROXY env var on the Grid node (http://USER:PASS@host:port). Browser-level proxy capabilities do not support auth directly.
Free trial on rotating residential -- 10 minutes setup, no credit card.