0

Here is my construction of my code and the Problem is, that the code is not running in in this case 2 (range(2)) different browsers which act at the same time. Instead of that, the programm does double the code and run it only in one browser. How do i get the code running in multiple browsers? Thanks

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time, requests, cfscrape, threading
from time import gmtime, strftime
from termcolor import colored
from threading import Thread

driver = 
webdriver.Chrome(executable_path="...")

def main():

    def gotohomepage():
        ...
    gotohomepage()


    def cookies():
        ...
    cookies()


    def queuechecker():
        ...
    queuechecker()


    def retrieving_productpage1():
        ...
    retrieving_productpage1()


    def gettingProductUrl():
        ...
    gettingProductUrl() 


threads = []

for i in range(2):
    t = threading.Thread(target=main)
    threads.append(t)
   t.start()

for thread in threads:
    t.join()

main()
Gamex
  • 1
  • 1

1 Answers1

0

The reason, why this is happening, is because you have declared the webdriver globally, which is causing the browser to be opened only once. However, you are executing the code twice via thread and that is why you are getting this output.

Possible solution: Try moving the webdriver initialization inside main, which would lead to open a new browser in the second go.

Example: https://www.lambdatest.com/blog/parallel-testing-in-selenium-webdriver-with-python-using-unittest/