简体   繁体   English

如何使用c#和Selenium chrome驱动程序加载特定的Google Chrome配置文件?

[英]How to load specific google chrome profile using c# & Selenium chrome driver?

I need to load my current google chrome profile with all the extensions/cookies/logins & passwords for sites using C# & Selenium chrome driver. 我需要使用C#和Selenium chrome驱动程序加载我当前的Google Chrome配置文件以及网站的所有扩展程序/ Cookie /登录名和密码。 Please help me to put correct code lines in the correct places. 请帮我把正确的代码行放在正确的位置。

I found some info how people did this with python , but even in those threads there are no answers where to put that code. 我找到了一些人们如何使用python进行此操作的信息,但即使在这些线程中也没有答案在哪里放置代码。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
IWebDriver Browser;

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{


IWebElement element;

Browser = new OpenQA.Selenium.Chrome.ChromeDriver();
Browser.Manage().Window.Maximize();
Browser.Navigate().GoToUrl("https://google.com");
Thread.Sleep(3000);

}

private void button2_Click(object sender, EventArgs e)
{
Browser.Quit();
}

Code I provided successfully opens an empty google chrome profile. 我提供的代码成功打开一个空的谷歌浏览器配置文件。 I need the selenium chrome driver to open google chrome with my google chrome profile instead of empty profile. 我需要selenium chrome驱动程序用我的谷歌浏览器配置文件而不是空配置文件打开谷歌浏览器。

Welcome to SO. 欢迎来到SO。 You can use the chromeoptions. 你可以使用chromeoptions。

ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=/path/to/your/custom/profile");

Refer to the http://chromedriver.chromium.org/capabilities , for more information. 有关更多信息,请参阅http://chromedriver.chromium.org/capabilities Make sure to use the chrome option with driver. 确保将chrome选项与驱动程序一起使用。

IWebDriver driver = new ChromeDriver(options);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM