fysh711426 / UndetectedChromeDriver

GNU General Public License v3.0
166 stars 61 forks source link

how to work with two driver same time #1

Closed training0112 closed 2 years ago

training0112 commented 2 years ago

thanks for sharing, i tried and it works fine, but i faced a problem, after creating 2 drivers(driver and driver2), go to different or same url, only 1 works, the other don't do anything, and driver2 use same options with driver, this doesn't happen with standard version

var options = new ChromeOptions();
options.AddArgument("--mute-audio");
options.AddArgument("--disable-gpu");
options.AddArgument("--disable-dev-shm-usage");
options.AddArgument($"--window-size=500,900");
options.AddArgument("--window-Position=0,0");
using var driver = UndetectedChromeDriver.Create(
    options: options,
    userDataDir: userDataPath,
    driverExecutablePath: driverExecutablePath,
    browserExecutablePath: browserExecutablePath);
driver.GoToUrl("https://www.bing.com");

var options2 = new ChromeOptions();
options2.AddArgument("--mute-audio");
options2.AddArgument("--disable-gpu");
options2.AddArgument("--disable-dev-shm-usage");
options2.AddArgument($"--window-size=500,900");
options2.AddArgument("--window-Position=500,0");
using var driver2 = UndetectedChromeDriver.Create(
    options: options2,
    userDataDir: userDataPath,
    driverExecutablePath: driverExecutablePath2,
    browserExecutablePath: browserExecutablePath);
driver2.GoToUrl("https://www.selenium.dev/");

in this case only driver go https//www.bing.com

1

training0112 commented 2 years ago

the problem is solved, just use a different userDataPath for each driver

fysh711426 commented 2 years ago

Sorry for the late reply, I am also researching this issue these days. You are right, must use independent userDataDir and options to start multiple instances.

Now I have implemented the function of automatically creating userDataDir in new version, if userDataDir is not specified, the code will automatically generate a temporary directory and delete it after the end.