Marc B.
Marc B.

Reputation: 104

What's the right way to use several webdriver of selenium simultaneously?

The goal is to write a python script that opens a specific website, fills out some inputs and then submits it. This should be done with different inputs for the same website simultaneously.

I tried using Threads from threading and some other things but i can't make it work simultaneously.

from selenium import webdriver
import time
from threading import Thread


def test_function():
    driver = webdriver.Chrome()
    driver.get("https://www.google.com")
    time.sleep(3)


if __name__ =='__main__':
    Thread(target = test_function()).start()
    Thread(target = test_function()).start()

So executing this code the goal is that 2 chrome windows will open simultaneously, go to google and then wait for 3 seconds. Now all that's done is that the function is called two times in a serial manner.

Upvotes: 0

Views: 55

Answers (2)

Corey Goldberg
Corey Goldberg

Reputation: 60604

Now all that's done is that the function is called two times in a serial manner.

The behavior you are seeing is because you are calling test_function() when you pass it as a target. Rather than calling the function, just assign the callable name (test_function).

like this:

Thread(target=test_function).start()

Upvotes: 1

RockinWatson
RockinWatson

Reputation: 111

You will need a testing framework like pytest to execute tests in parallel. Here is a quick setup guide to get you going.

PythonWebdriverParallel

Upvotes: 0

Related Questions