I\'m trying to create multiple chrome threads for each item in the list and execute the function for each item from list simultaneously, but having no idea where to even start a
Similar to the answer here, you can start multiple threads of Chrome.
execute_chrome
in this caseThread
call, e.g. args=(elem, )
my_selenium_tests.py
run the script preferably from the command line and not from an interactive environment (e.g. a Jupyter notebook)
from selenium import webdriver
import threading
import random
import time
number_of_threads = 4
def execute_chrome(url):
chrome = webdriver.Chrome()
chrome.get(url)
time.sleep(1 + random.random() * 5)
driver.quit()
urls = ('https://www.google.com',
'https://www.bing.com',
'https://www.duckduckgo.com',
'https://www.yahoo.com')
threads = []
for i in range(number_of_threads):
t = threading.Thread(target=execute_chrome, args=(urls[i], ))
t.start()
threads.append(t)
for thread in threads:
thread.join()