0

Is there a way to have one chromedriver process instance running but have two different Selenium WebDrivers connected to it where both run code at the same time? (e.g. navigate to a URL, click on a button, ...)?

I know that I can open two different pages on the same headless browser and switch between them, but I want to do both processings simultaneously, so that won't work for me.

I'm writing this in Java.

Mahdi
  • 1,871
  • 2
  • 24
  • 41

1 Answers1

0

You can initiate two ChromeDriver initiated browsing context simultaneously as follows:

ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");

WebDriver driver1 = new ChromeDriver(options);
driver1.get("https://www.google.com");

WebDriver driver2 = new ChromeDriver(options);
driver2.get("https://www.bing.com/");

and switch focus between them as follows:

((JavascriptExecutor) driver1).executeScript("window.focus();");
((JavascriptExecutor) driver2).executeScript("window.focus();");
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352