0

I am running multiple selenium instances and I am encountering a problem.

My code searches google by breaking down a string and typing it each character at a time using a loop.

search_box = browser.find_element(By.NAME, "q")
time.sleep(2)
print("Typing...")
actions.move_to_element(search_box)
for i in range(len(SEARCH)):
   search_box.send_keys(SEARCH[i])
   time.sleep(0.15)

after the search it deletes each character one by one

search_box = browser.find_element(By.NAME, "q")
actions.move_to_element(search_box)
for i in range(len(SEARCH)):
    search_box.send_keys(Keys.BACK_SPACE)
    time.sleep(0.15)

running one instance by itself works fine but running multiple it doesn't type or delete as it should. Some times I get half sentences or it doesn't delete the whole sentence. Looks like the loop get's interrupted by something I just can't figure it out

More Information:


                    chrome_options.add_argument('--allow-running-insecure-content')
                    chrome_options.add_argument('--ignore-certificate-errors')
                    chrome_options.add_argument('--disable-dev-shm-usage')
                    chrome_options.add_argument('--disable-gpu')
                    chrome_options.add_argument(fr'--user-data-dir={PATH_USERDATA}{instance_number}')
                    chrome_options.add_argument(f'--profile-directory={chromeProfile}')
                    chrome_options.add_argument(f'--proxy-server={proxy}')
                    chrome_options.add_argument(f'user-agent={userAgent}')
                    chrome_options.add_argument('--blink-settings=imagesEnabled=false')
                    chrome_options.add_argument('--disable-features=OptimizationGuideModelDownloading,OptimizationHintsFetching,OptimizationTargetPrediction,OptimizationHints')

                    print("Starting up Session.....")
                    print(f"Current IP = {proxy}")

                    browser = uc.Chrome(options=chrome_options)
                    pid = browser.service.process.pid
                    process = psutil.Process(pid)
                    browser.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")
                    browser.execute_cdp_cmd('Network.setUserAgentOverride', {"userAgent": f'{userAgent}'})
                    browser.execute_cdp_cmd('Network.setBlockedURLs', {"urls": ["www.gstatic.com", 'www.google.com','optimizationguide-pa.googleapis.com']})
                    browser.execute_cdp_cmd('Network.enable', {})
                    actions = ActionChains(browser)

I have no idea what to do and would like help, Thank you!

EDIT: I run the instances by putting the code in a function and calling it at the end. and just running it one by one

maloni
  • 31
  • 3

0 Answers0