I wrote a code to open 4 Browser instance at a time but i need to select each browser instance separately.
for example if there are 4 Browser instance with 4 different profiles.1st Browser 1 (Profile 1) opens after 10 seconds Browser 2 (profile 2) opens and so on. After Profile 4 Opens i can see Profile 4 windows on screen but i need to switch to profile 1 browser instance (view on screen) and do some task then go to profile 2– 3—4.

My code below —

def create_processes(profile_dirs, brave_path, start_value, end_value, num_processes):
    for num in range(start_value, end_value + 1, num_processes):
        processes = []
        try:
            for process_num in range(num, min(num + num_processes, end_value + 1)):
                profile_dir = f"{profile_dirs[0]}Profile {process_num}\PC"
                websites = ["brave://version/"]  
                process = multiprocessing.Process(target=browser_operation, args=(profile_dir, brave_path, process_num, websites))
                processes.append(process)
        except Exception as e:
            print(f"Error occurred while creating processes: {e}")
    
        
        for process in processes:
            process.start()
            time.sleep(10) 
        
        for process in processes:
            process.join()

def browser_operation(profile_dir, brave_path, num, websites):
    try:
        option = uc.ChromeOptions()
        option.add_argument(f'--user-data-dir={profile_dir}')
        option.binary_location = brave_path
        option.headless = False
        browser = uc.Chrome(options=option)
        print(f"Opened browser for Profile {num}")
        
        for website in websites:
            browser.get(website)
            time.sleep(5)  
        time.sleep(10)
        
        #task code Here
        #task code Here
        #task code Here
        
        time.sleep(100)
        browser.close()
        browser.quit()
        print(f"Closed browser for Profile {num}")
    except Exception as e:
        print(f"Error occurred in browser {num}: {e}")

if __name__ == "__main__":
    try:
        brave_path = [f"{brave_location}"]
        profile_dirs = [f"{location}"]  
        num_profiles_simultaneously = 4
        create_processes(profile_dirs, brave_path, start_value, end_value, num_profiles_simultaneously)
        
    except Exception as e:
        print(f"Main process error: {e}")

I tried using win32gui,pygetwindow.

Is there anyway to do this?

New contributor

kpatti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.