Explain in detail! Selenium really bypasses webdriver detection

Table of contents

Foreword:

1. What is really bypassing browser detection?

2. Ordinary start webdriver

3. Js injection really bypasses the detection properties of webdriver

js injected file [stealth.min.js]


Foreword:

Selenium is a popular open source testing tool used for web application testing. It enables testers to write automated tests in various programming languages ​​to test the functionality of web applications. Selenium tests can be run on many different browsers and operating systems.

Selenium testing tool is an excellent tool for automating web application testing. It can be used to test the functionality of web applications on various browsers and operating systems. Selenium software testing is a great way to automate your web application testing.

1. What is really bypassing browser detection?

  • https://bot.sannysoft.com This is the real detection URL of chrome

  • Why the emphasis on bypassing webdriver attribute detection?

Some URLs are detected by webdriver so that Selenium cannot obtain elements, cannot control buttons, etc.

1. The effect of opening chrome in the PC environment

Generally speaking, even if the normal webdriver is enabled, it will be marked red. The above is to open the detection properties of the local chrome

2. Ordinary start webdriver

  • upper size

from selenium import webdriver
class WebDriverChrome(object):
    def __init__(self):
        self.driver = self.StartWebdriver()
    def StartWebdriver(self):
        options = webdriver.ChromeOptions()
        options.add_argument("start-maximized")
        options.add_experimental_option("excludeSwitches", ["enable-automation"])
        options.add_experimental_option("useAutomationExtension", False)
        driver = webdriver.Chrome(options=options)
        return driver
    def RunStart(self):
        self.driver.get('https://bot.sannysoft.com')
        # time.sleep(10)
        # self.driver.quit()
if __name__ == '__main__':
    Crawl = WebDriverChrome()
    Crawl.RunStart()

3. Js injection really bypasses the detection properties of webdriver

  • Why does my injected js property work?

This js file is used in pyppetter to bypass webdriver detection

Now import directly into chrome launched by Selenium

upper code:

from selenium import webdriver
class WebDriverChrome(object):
    def __init__(self):
        self.driver = self.StartWebdriver()
    def StartWebdriver(self):
        options = webdriver.ChromeOptions()
        options.add_argument("start-maximized")
        options.add_experimental_option("excludeSwitches", ["enable-automation"])
        options.add_experimental_option("useAutomationExtension", False)
        driver = webdriver.Chrome(options=options)
        with open('./stealth.min.js') as f:
            js = f.read()
        driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
            "source": js
        })
        return driver
    def RunStart(self):
        self.driver.get('https://bot.sannysoft.com')
        # time.sleep(10)
        # self.driver.quit()
if __name__ == '__main__':
    Crawl = WebDriverChrome()
    Crawl.RunStart()

js injected file [stealth.min.js]

If the naming is not uniform, it can be read only if it is required

method of obtaining:

Install node.js

 npx extract-stealth-evasions

A stealth.min.js file will be generated under the folder where you execute the command

 As someone who has been here, I also hope that everyone will avoid some detours, and I hope it can help you. (WEB automated testing, interface automated testing, automated test development, big factory interview questions, resume templates, etc.), I believe it will make you better progress!

 

Guess you like

Origin blog.csdn.net/DJ355/article/details/131116025