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.19k stars 1.1k forks source link

Python undetectable_webdriver won't open in a loop #377

Open sirLessClicks opened 2 years ago

sirLessClicks commented 2 years ago

I am trying to open a site multiple times in a loop to test if different credentials have expired so that I can notify our users. I'm achieving this by opening the database, getting the records, calling the chrome driver to open the site, and inputting the values into the site. The first loop works but when the next one initiates the driver hangs and eventually outputs the error:

    "unknown error: cannot connect to chrome at 127.0.0.1:XXXX from chrome not reachable"

This error commonly occurs when there is already an instance running. I have tried to prevent this by using both driver.close() and driver.quit() when the first loop is done but to no avail. I have taken care of all other possibilities of detection such as using proxies, different user agents, and also using the undetected_chromedriver by https://github.com/ultrafunkamsterdam/undetected-chromedriver.

The core issue I am looking to solve is being able to open an instance of the chrome driver, close it and open it back again all in the same execution loop until all the credentials I am testing have finished. I have abstracted the code and provided an isolated version that replicates the issue:

# INSTALL CHROMDRIVER USING "pip install undetected-chromedriver"
import undetected_chromedriver.v2 as uc

# Python Libraries
import time

options = uc.ChromeOptions()

options.add_argument('--no-first-run')

driver = uc.Chrome(options=options)

length = 8
count = 0
if count < length:
    print("Im outside the loop")
    while count < length:
        print("This is loop ",count)
        time.sleep(2)
        with driver:
            print("Im inside the loop")
            count =+ 1
            driver.get("https://google.com")
            time.sleep(5)
            print("Im at the end of the loop")
            driver.quit()   # Used to exit the browser, and end the session
            # driver.close()  # Only closes the window in focus 

Any solutions, suggestions, or workarounds would be greatly appreciated.

ultrafunkamsterdam commented 2 years ago

whatever you do, remove the time sleepOn Nov 30, 2021 00:51, sirLessClicks @.***> wrote: I am trying to open a site multiple times in a loop to test if different credentials have expired so that I can notify our users. I'm achieving this by opening the database, getting the records, calling the chrome driver to open the site, and inputting the values into the site. The first loop works but when the next one initiates the driver hangs and eventually outputs the error: "unknown error: cannot connect to chrome at 127.0.0.1:XXXX from chrome not reachable"

This error commonly occurs when there is already an instance running. I have tried to prevent this by using both driver.close() and driver.quit() when the first loop is done but to no avail. I have taken care of all other possibilities of detection such as using proxies, different user agents, and also using the undetected_chromedriver by https://github.com/ultrafunkamsterdam/undetected-chromedriver. The core issue I am looking to solve is being able to open an instance of the chrome driver, close it and open it back again all in the same execution loop until all the credentials I am testing have finished. I have abstracted the code and provided an isolated version that replicates the issue:

INSTALL CHROMDRIVER USING "pip install undetected-chromedriver"

import undetected_chromedriver.v2 as uc

Python Libraries

import time

options = uc.ChromeOptions()

options.add_argument('--no-first-run')

driver = uc.Chrome(options=options)

length = 8 count = 0 if count < length: print("Im outside the loop") while count < length: print("This is loop ",count) time.sleep(2) with driver: print("Im inside the loop") count =+ 1 driver.get("https://google.com") time.sleep(5) print("Im at the end of the loop") driver.quit() # Used to exit the browser, and end the session

driver.close() # Only closes the window in focus

Any solutions, suggestions, or workarounds would be greatly appreciated.

—You are receiving this because you are subscribed to this thread.Reply to this email directly, view it on GitHub, or unsubscribe.Triage notifications on the go with GitHub Mobile for iOS or Android.

sirLessClicks commented 2 years ago

Is the time.sleep no longer used to control the flow of the application? I use time.sleep in all other aspects of my application. I would appreciate any insight as to how to get a new instance of the driver in the loop. Also, any insight into the driver itself if it doesn't all open multiple instances in the same execution.

saintdanelimbu commented 2 years ago

Have you solved this problem?

Avnsx commented 2 years ago

Have the same issue

DGaffney commented 2 years ago

Also running into this