Skip to content

Integrating Selenium with XProxy

Ask AI

Ready taskAdd this to my code

Coding agents

Claude CodeOpens the desktop appCodexOpens the desktop appCursorOpens the app from the web

Chat assistants

Open in ChatGPTNew tabOpen in ClaudeNew tab

Copy

View as MarkdownPlain text for AI tools
See the prompt
Read https://xproxy.io/document/integrating-selenium-with-xproxy.md, the XProxy guide "Integrating Selenium with XProxy". If you cannot open links, download them with curl. Then add it to my project: read my code, use the language and libraries it already uses, keep proxy logins and API keys in environment variables, and show me how to test it.
Other XProxy guides, each with a Markdown copy at its URL + .md, are listed in https://xproxy.io/llms.txt.

The app opens with the prompt filled in. Nothing runs until you press Enter.

Send Selenium and Chrome through an XProxy mobile proxy, and change the IP from your Python code.

In short

Proxy in Chrome options

One --proxy-server argument sends Chrome through your XProxy proxy.

New IP from code

Call one URL on your panel before you start Chrome. The modem gets a new IP in a few seconds.

Easy to check

Open an IP page and print it. It must match the Public IP of that proxy in your panel.

You need: Python 3 with Selenium and Chrome installed, and an XProxy panel with a working modem.

Chrome needs a proxy without a password

Chrome cannot take a username and password in --proxy-server. Use the Whitelist IP login for this script:

  1. In your XProxy panel open Proxy Settings → Login and turn on Whitelist IP (Basic plan or higher).
  2. Add the public IP of the computer that runs Selenium.
  3. In Proxy Management, click Export Proxy. Set Protocol to HTTP and Credentials to No credentials (host:port), then click Copy All.
Need a password instead? Use Playwright: it takes a username and a password in its launch options. More about the two login methods: Copy a proxy in the right format.

Open a page through XProxy

selenium_xproxy.py
from selenium import webdriver
from selenium.webdriver.common.by import By

options = webdriver.ChromeOptions()
options.add_argument("--proxy-server=http://192.168.1.10:4001")  # from Export Proxy
options.add_argument("--headless=new")  # optional: no window

driver = webdriver.Chrome(options=options)
try:
    driver.get("https://api.ipify.org?format=json")
    print(driver.find_element(By.TAG_NAME, "body").text)  # {"ip":"..."}
finally:
    driver.quit()

Needs pip install selenium. Selenium 4.6 or newer finds the Chrome driver for you.

Change the IP from code

Position 1 is the first modem, the one on port 4001 when the starting port is 4000. The code calls the rotation API, then asks the panel for the modem's status until it says MODEM_READY. All calls are in How to change / rotate IP.

Panel asks for a login? If Force API Auth is on, these calls need your dashboard login: add auth=("USER", "PASS") to each requests.get.

Check it works

  1. Run the first script. It prints an IP address.
  2. In Proxy Management, look at the Public IP of that proxy (marked 1). It is the same IP.
  3. Run the second script. It prints a new IP twice: the one from the panel call and the one Chrome sees.
Proxy Management table with the Public IP of the first proxy marked (demo data)
1 The Public IP your script should print. Demo data.

Something not working?

You seeWhat to do
Chrome shows a proxy error page, or asks for a loginThe proxy still wants a password. Add your computer's public IP to Whitelist IP as shown above, or use Playwright with a username and password.
Connection refused or timed outThe address is not reachable from your computer. A LAN only address works only on your own network: use Public address or VPS relay (public access). Also check the port in Proxy Management.
The printed IP is your own IPThe request did not go through the proxy. Check that the proxy is passed to the request, the browser or the crawler, and that it is not set only for http or only for https.
The rotation call fails or says status is falseCheck the position number and the panel address. If Force API Auth is on, add your dashboard login to the call.
The IP is the same after rotatingSometimes the carrier gives the modem the same IP. Rotate again. The status call can also answer COLLISION_IP when IP unchanged detect is on in Rotation Settings.

What next?

Change the IP on a timer, or copy your proxies in another format.

Still stuck?A technician can look at your device with a one-time PIN, or chat with us on Telegram.