![](/img/trans.png)
[英]Can't start Chrome Driver with saved profile on Selenium with C#
[英]How to load specific google chrome profile using c# & Selenium chrome driver?
我需要使用C#和Selenium chrome驅動程序加載我當前的Google Chrome配置文件以及網站的所有擴展程序/ Cookie /登錄名和密碼。 請幫我把正確的代碼行放在正確的位置。
我找到了一些人們如何使用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();
}
我提供的代碼成功打開一個空的谷歌瀏覽器配置文件。 我需要selenium chrome驅動程序用我的谷歌瀏覽器配置文件而不是空配置文件打開谷歌瀏覽器。
歡迎來到SO。 你可以使用chromeoptions。
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=/path/to/your/custom/profile");
有關更多信息,請參閱http://chromedriver.chromium.org/capabilities 。 確保將chrome選項與驅動程序一起使用。
IWebDriver driver = new ChromeDriver(options);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.