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

前端 未结 10 850
既然无缘
既然无缘 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:11

    I would like to add a Java alternative to the cdp command method mentioned by pguardiario

    Map params = new HashMap();
    params.put("source", "Object.defineProperty(navigator, 'webdriver', { get: () => undefined })");
    driver.executeCdpCommand("Page.addScriptToEvaluateOnNewDocument", params);
    

    In order for this to work you need to use the ChromiumDriver from the org.openqa.selenium.chromium.ChromiumDriver package. From what I can tell that package is not included in Selenium 3.141.59 so I used the Selenium 4 alpha.

    Also, the excludeSwitches/useAutomationExtension experimental options do not seem to work for me anymore with ChromeDriver 79 and Chrome 79.

提交回复
热议问题