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

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

    Before (in browser console window):

    > navigator.webdriver
    true
    

    Change (in selenium):

    // C#
    var options = new ChromeOptions();
    options.AddExcludedArguments(new List() { "enable-automation" });
    
    // Python
    options.add_experimental_option("excludeSwitches", ['enable-automation'])
    

    After (in browser console window):

    > navigator.webdriver
    undefined
    

    This will not work for version ChromeDriver 79.0.3945.16 and above. See the release notes here

提交回复
热议问题