【发布时间】: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