Selenium webdriver: Modifying navigator.webdriver flag to prevent selenium detection

前端 未结 10 839
既然无缘
既然无缘 2020-11-22 00:57

I\'m trying to automate a very basic task in a website using selenium and chrome but somehow the website detects when chrome is driven by selenium and blocks every request.

10条回答
  •  长发绾君心
    2020-11-22 01:12

    Finally this solved the problem for ChromeDriver, Chrome greater than v79.

    ChromeOptions options = new ChromeOptions();
    options.addArguments("--disable-blink-features");
    options.addArguments("--disable-blink-features=AutomationControlled");
    ChromeDriver driver = new ChromeDriver(options);
    Map params = new HashMap();
    params.put("source", "Object.defineProperty(navigator, 'webdriver', { get: () => undefined })");
    driver.executeCdpCommand("Page.addScriptToEvaluateOnNewDocument", params);
    

提交回复
热议问题