【问题标题】:Run multiple chrome (profiles) instances for automation task为自动化任务运行多个 chrome(配置文件)实例
【发布时间】:2016-04-16 02:29:41
【问题描述】:

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

我使用 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");
        }
    }
}

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

有什么帮助吗?

【问题讨论】:

  • 感谢您的帮助。如果将整个配置文件复制到另一个位置并将其设置为 user-data-dir,则可以正常工作。

标签: c# selenium automation selenium-chromedriver multiple-instances


【解决方案1】:

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

请使用不同的用户数据目录启动每个 chrome 实例。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-07
    • 1970-01-01
    • 2021-03-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多