Search code examples
pythonseleniumpoolui-testing

How can I open async several selenium webdriver using python


Please help! I want to open several webdrivers and for each do different actions, for example for first opened webdriver do login, for second registration etc. I try to use Pool library, but it doesn't work correctly, it opens webdrivers not paraller.

from multiprocessing import Pool
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

class C:
    def log(self,  url):
        print("1")
        chrome_options = Options()
        chrome_options.add_argument("--start-maximized")
        driver = webdriver.Chrome("C:/Users/path")
        driver.get(url)

    def reg(self, url):
        print("2")
        chrome_options = Options()
        chrome_options.add_argument("--start-maximized")
        driver = webdriver.Chrome("C:/Users/path")
        driver.get(url)


    def f(self, *name):
        return name

    def run(self):
        pool = Pool(processes=2)
        pool.map(self.f, (self.log("someurl?form=sign_in"), self.reg("someurl?form=sign_up")))

if __name__ == '__main__':
    c = C()
    c.run()

Solution

  • I think Selenium Grid 4 is what you're looking for.