0

I am able to run multiple chrome windows using selenium and python but the windows run one after another,One window complete its tasks and then move to the next window, But I want it to run parallel like multiple windows should open at same time and all clicks should be performed in a parallel way, let say steps are to open Facebook, Login, Like Posts these three steps should be done in all chrome windows at the same time if 30 windows are open then 30 windows should ope facebook at same time and perform action.

Here is my code that I am using to run one chrome window:

browser=webdriver.Chrome('C:/chromedriver.exe')
browser.get("facebook.com")
input = browser.find_element_by_xpath('//input[@type="email"]')
time.sleep(1)
input.click()

Please let me know what can I use in python to perform tasks in a parallel way

1 Answer 1

1

Try to use Threading library:

import threading

def event():
    browser=webdriver.Chrome('C:/chromedriver.exe')
    browser.get("facebook.com")
    input = browser.find_element_by_xpath('//input[@type="email"]')
    time.sleep(1)
    input.click()
    browser.quit()

threads = []
for _ in range(30):
    thread = threading.Thread(target=event)
    threads.append(thread)
    thread.start()

for thread in threads:
    thread.join()

This code should allow to perform same actions 30 times in parallel

P.S. If you're looking for web-site performance testing you can try The Grinder tool

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer, Can I pass function event with some parameters like I want to provide events with parameters as event(Name,Email,Phone)
Yes. Define it as def event(Name,Email,Phone) and then call as thread = threading.Thread(target=event, args=(Name,Email,Phone,) )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.