Java runner → configured proxy → WebDriver service
remote browser → its own route → website

สำหรับเส้นทางแรก ให้ตั้งค่าตัวประมวลผลคำสั่ง Java:

import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URI;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.HttpCommandExecutor;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.http.ClientConfig;

var proxy = new Proxy(Proxy.Type.HTTP,
    new InetSocketAddress("proxy.example", 8080));
var config = ClientConfig.defaultConfig()
    .baseUri(URI.create("https://grid.example/"))
    .proxy(proxy);
var executor = new HttpCommandExecutor(config);
var driver = new RemoteWebDriver(executor, new ChromeOptions());

ใช้ปลายทาง Grid จริง รวมพาธที่นำไปใช้งานด้วย คงตัวเลือก Chrome ที่จำเป็นไว้ และจบเซสชันด้วย driver.quit()

นี่คือ java.net.Proxy สำหรับการเชื่อมต่อ HTTP ของโปรแกรม Java ส่วน capability org.openqa.selenium.Proxy ของ Selenium ควบคุมทราฟฟิกหน้าเว็บของเบราว์เซอร์แทน ใช้เพิ่มเฉพาะเมื่อเส้นทางที่สองต้องการพร็อกซีด้วย

ความล้มเหลวในการสร้างเซสชันหรือส่งคำสั่งเป็นปัญหาของเส้นทางแรก การเปิดหน้าเว็บในภายหลังอาจล้มเหลวที่เส้นทางที่สอง การยืนยันตัวตนกับตัวกลางของโปรแกรม Java ต้องใช้วิธีที่ HTTP transport นั้นรองรับ callback ยืนยันตัวตนของเบราว์เซอร์ไม่ได้ตั้งค่าส่วนนี้

บทความที่เกี่ยวข้อง