i have scenario where i go to a webpage and open each link in a new window and check for specific documents but its taking enormous time to go through each link so is there a way to increase performance using multi-threading
known problem
selenium is not thread safe
but i can create multiple instances of driver for each thread which takes care of this problem
current code which i am using
for tag in self.driver.find_elements_by_xpath('//body//a[@href]'):
current_window = self.driver.current_window_handle
if href:
self.driver.execute_script('window.open(arguments[0]);', href)
time.sleep(10)
new_window = [window for window in self.driver.window_handles if window != current_window][0]
self.driver.switch_to.window(new_window)
# Execute required operations
func_url=self.driver.current_url
self.driver.close()
self.driver.switch_to.window(current_window)
if not func_url:
continue
if re.search('\.(?:pdf|png|jpg|doc|ppt|zip)',func_url):
cat=fd.findCat(func_url)
fd.findDate(func_url)
time.sleep(10)
but i can create multiple instances of driver for each thread which takes care of this problemso what is the question?