SeleniumHQ / seleniumhq.github.io

Official Selenium website and documentation
https://selenium.dev
Apache License 2.0
1.13k stars 1.32k forks source link

[🐛 Bug]: Dynamic proxy failure, ask how to achieve #2051

Open lxtqq opened 2 hours ago

lxtqq commented 2 hours ago

What happened?

In the test, the IP is not a proxy IP,
curl-x http://xxxx:xxxxx@xxxx.xxx.com:8091 http://httpbin.org/ip indicates that the IP address is inconsistent each time
Then the agent is OK, that is selenium configuration error

What browsers and operating systems are you seeing the problem on?

disposition

My Google is       113.0.5672.93
Google Drive is   113.0.5672.24

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.11.0</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-devtools-v113</artifactId>
            <version>4.11.0</version>
        </dependency>

CODE

import org.openqa.selenium.By;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collections;
import java.util.concurrent.TimeUnit;

public class WebDriverManager {

    private static final Logger log = LoggerFactory.getLogger(WebDriverManager.class);
    private static final String PROXIES_CONFIG = "dtqybf.xiongmaodaili.com:8091";

    public static void main(String[] args) {
        WebDriver driver = getWebDriver();
        driver.get("http://httpbin.org/ip");
        WebElement body = driver.findElement(By.tagName("body"));
        driver.quit();
    }

    public static WebDriver getWebDriver() {
        System.setProperty("webdriver.chrome.driver", "C:/Users/aa/AppData/Local/Google/Chrome/Application/chromedriver.exe");

        // 配置ChromeOptions
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--disable-dev-shm-usage");
        options.addArguments("--disable-gpu");
        options.addArguments("--remote-allow-origins=*");
        options.addArguments("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.5672.92 Safari/537.3");
        options.addArguments("--disable-blink-features=AutomationControlled");
        options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
        if (PROXIES_CONFIG != null && !PROXIES_CONFIG.isEmpty()) {
            String selectedProxy = "0IWHbXLW:fiUPnLxm@" + PROXIES_CONFIG;
            Proxy seleniumProxy = new Proxy();
            seleniumProxy.setHttpProxy(selectedProxy);
            seleniumProxy.setFtpProxy(selectedProxy);
            seleniumProxy.setSslProxy(selectedProxy);
            options.setCapability(CapabilityType.PROXY, seleniumProxy);
            options.setAcceptInsecureCerts(true);
        }
        ChromeDriver driver = new ChromeDriver(options);
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        return driver;
    }
}
github-actions[bot] commented 2 hours ago

@lxtqq, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!