I have been trying to run chrome and firefox webdrivers simultaneously using selenium. Following is the code I have tried:
drivers = [chromedriver,firefoxdriver]
with concurrent.futures.ThreadPoolExecutor() as executor:
futures = []
for driver_name in drivers:
futures.append(executor.submit(
check_url,url,driver_type = driver_name))
for future in concurrent.futures.as_completed(futures):
try:
print(future.result())
except requests.ConnectTimeout:
print('ConnectTimeout')
Here check_url is a function where I pass the URL and the driver exe path. I have tried keeping both the browsers as headless and on UI as well but one or the other keeps on giving errors. Below stated is the most common error:
The element reference of <li> is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
I am able to run both the webdrivers separately very smoothly but I need to save time and run the script for both browsers together. I've read that selenium webdriver is not thread-safe. Though I used the traditional multithreading and multiprocessing codes I cannot seem to find a suitable solution for this. Thank you.