fysh711426 / UndetectedChromeDriver

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

launch Multiple UndetectedChromeDriver in Parallel #38

Open zackeddd opened 1 year ago

zackeddd commented 1 year ago

When opening multiple browsers in parallel and sending the keys, only the browser in the front is the one who receives the key, while the browsers in the back do not receive the keys.

EX:

issues

` Code Used :

    static void Main(string[] args)
    {

        string UserDataDir = @"C:\Users\admin\Desktop\Selenium Project\Selenium Project\bin\Debug\Profiles";
        string ChromeDriver = @"C:\Users\admin\Desktop\Selenium Project\Selenium Project\bin\Debug\Drivers";

        int from = 1;
        int to = 2;

        Parallel.For(from, to + 1, i =>
        {

            using (var driver = UndetectedChromeDriver.Create(driverExecutablePath: ChromeDriver + "\\" + i.ToString() + "\\chromedriver.exe", userDataDir: UserDataDir + "\\" + i.ToString()))
            {
                // Navigate to Google
                driver.Navigate().GoToUrl("https://www.google.com");

                // Find the search box element and send the search key
                IWebElement searchBox = driver.FindElement(By.Name("q"));
                searchBox.SendKeys("key N" + i.ToString());

                // Submit the search
                searchBox.Submit();

                Thread.Sleep(TimeSpan.FromSeconds(30));

            }

        });

        Console.ReadKey(true);

    }`
thenik commented 1 year ago

Hey, it is standart behaviour. You have to make browser focused + active till send any key .

JvB94 commented 1 year ago

Hey, it is standart behaviour. You have to make browser focused + active till send any key .

are you sure? i run several chromedrivers as well and never need a focus. Is the only related to UndetectedChromeDriver? How you force focus?

fysh711426 commented 1 year ago

The problem should be here. (same as thenik)
https://stackoverflow.com/questions/70423331/selenium-locate-element-fails-when-chrome-in-background

Solution: change parallel to sync.

zackeddd commented 1 year ago

The problem should be here. (same as thenik) https://stackoverflow.com/questions/70423331/selenium-locate-element-fails-when-chrome-in-background

Solution: change parallel to sync.

when i use async the code wait for each instance to complete before moving on to the next one. This may take longer to complete compared to the parallel execution.