运行 多个 chrome(配置文件)自动化任务实例

Run multiple chrome (profiles) instances for automation task

我想 运行 多个 chrome 具有不同配置文件的实例(每个配置文件都有自己的 cookie)同时执行某些任务。例如,我想在 Google 上搜索 2 个帐户(每个帐户都有自己的代理)。

我使用 Visual Studio Community 2015。

这是我到目前为止所做的(没有代理):

namespace ChromeBot
{
    class Program
    {
        public static object Application { get; private set; }

        static void Main(string[] args)
        {
            //Set specific profile for Google Chrome
            var options = new ChromeOptions();
            options.AddArguments("user-data-dir=C:/Users/conta/AppData/Local/Google/Chrome/User Data/");
            options.AddArguments("--start-maximized");
            options.AddArguments("--profile-directory=Profile 1");


            //Create the reference for our browser 
            IWebDriver driver = new ChromeDriver(options);
            driver.Manage().Timeouts().SetPageLoadTimeout(new TimeSpan(0, 0, 0, 12));


            //Navigate to Google Page
            driver.Navigate().GoToUrl("http://www.google.com");


            //Find the element
            IWebElement element = driver.FindElement(By.Name("q"));


            //Perform ops
            element.SendKeys("cars");


            // Set specific profile for Google Chrome1
            var options1 = new ChromeOptions();
            options1.AddArguments("user-data-dir=C:/Users/conta/AppData/Local/Google/Chrome/User Data/");
            options1.AddArguments("--start-maximized");
            options1.AddArguments("--profile-directory=Profile 2");


            //Create the reference for our browser 1
            IWebDriver driver1 = new ChromeDriver(options1);

            driver.Manage().Timeouts().SetPageLoadTimeout(new TimeSpan(0, 0, 0, 12));

            //Navigate to Google Page 1
            driver1.Navigate().GoToUrl("http://www.google.com");

            //Find the element
            IWebElement element = driver.FindElement(By.Name("q"));


            //Perform ops
            element.SendKeys("smartphones");
        }
    }
}

当 运行 此代码打开每个配置文件时什么都不做..

有什么帮助吗?

当用户通过 chrome 驱动程序启动 chrome 时,它会打开 chrome 浏览器的新实例并锁定 user-data-dir。因此,如果任何其他实例尝试使用相同的 user-data-dir 打开,第二个实例不会响应。

请启动每个 chrome 具有不同 user-data-dir 的实例。