ultrafunkamsterdam / undetected-chromedriver

Custom Selenium Chromedriver | Zero-Config | Passes ALL bot mitigation systems (like Distil / Imperva/ Datadadome / CloudFlare IUAM)
https://github.com/UltrafunkAmsterdam/undetected-chromedriver
GNU General Public License v3.0
9.57k stars 1.14k forks source link

Multi-Threading - Typing Error #1243

Open NoizzyBots opened 1 year ago

NoizzyBots commented 1 year ago

So, I'm using Multi-Threading. 3.4.7 Version. Overall, everything works except typing. If I use send_keys(text), it works without any issues, but I have added typing with delay:

    def type_with_delay(self, element, text, driver):
        driver.execute_script("arguments[0].value = '';", element)
        for char in text:
            element.send_keys(char)
            time.sleep(uniform(0.1, 0.3))

    def type_with_delay_and_verify(self, element, text, driver):
        attempts = 0
        while attempts < 200:
            self.type_with_delay(element, text, driver)
            if element.get_attribute('value') == text:
                return
            element.clear()
            attempts += 1
            print(attempts)
        raise Exception(f'Failed to enter text "{text}" after {attempts} attempts')

If I type with delay, it starts to type a part of the text. It loses the focus on the browser since I'm using multi-threading.

P.S. I'm also creating a new WebDriver for each thread. If I'm using regular selenium, no issues at all, so it's something to do with this chromedriver.

    def create_driver_instance(self, proxy, user_agent, mock_timezone):
        while True:
            try:
                prefs = {'credentials_enable_service': False, 'profile.password_manager_enabled': False}
                options = uc.ChromeOptions()
                options.add_argument(f'--user-agent={user_agent}')
                if self.proxy_settings['Use_Proxy'] == 'y':
                    options.add_argument(f'--proxy-server=http://{proxy}')
                options.add_argument('--disable-blink-features=AutomationControlled')
                options.add_argument(f'--load-extension={os.getcwd()}/WebRTC')
                options.add_argument('--log-level=3')
                options.add_experimental_option('prefs', prefs)
                driver = uc.Chrome(options=options, user_multi_procs=True)
                break
            except:
                pass
        if mock_timezone:  # Call this only if mock_timezone was found.
            driver.execute_cdp_cmd("Emulation.setTimezoneOverride", {"timezoneId": mock_timezone})
        return driver
NoizzyBots commented 1 year ago

With single thread, there is no issues.

NoizzyBots commented 1 year ago

Also, the headless mode works excellent, with no issues. Does anyone else also have this problem?

lilcryptopump commented 4 months ago

@NoizzyBots Hello, did you solve this? Got same issue.

This workaround could work in some cases:

el.value("TEST")
el.dispatchEvent(new Event('input', { 'bubbles': true }));

But in my case it's not working.