A JavaScript Selenium script sends WebDriver commands to the remote server before that server’s browser can navigate anywhere. If the command connection must cross an HTTP proxy, configure the Builder’s WebDriver proxy:

const { Builder, Browser } = require("selenium-webdriver");

const driver = await new Builder()
  .forBrowser(Browser.CHROME)
  .usingServer(gridUrl)
  .usingWebDriverProxy("http://proxy.example.net:8080")
  .build();

gridUrl is the real Selenium server or hosted WebDriver endpoint. For a publicly reachable endpoint where that route is permitted, the HTTP proxy list supplies candidates for usingWebDriverProxy. Run the fragment inside an async CommonJS function. Quit the driver when the test session ends.

usingWebDriverProxy controls the JavaScript binding’s HTTP connections. It does not set Chrome’s proxy capability or a Chrome launch argument.

If browser traffic also needs an intermediary, supply the intended Chrome options separately. That browser runs on the remote machine, so its proxy endpoint must be reachable there. A loopback address on the script’s machine is not automatically a loopback service available to the remote browser.

Identify whether failure happens while creating the WebDriver session or while navigating a website. The two failures can involve different network clients and different proxy policies.

متعلقہ مضامین