0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

実際のブラウザーのプロファイルをWebDriverで使う

Last updated at Posted at 2021-07-15

普段使っているブラウザーのプロファイルをWebDriverで使いたい。

Chromeの場合

            var options = new ChromeOptions();
            options.AddArguments(@"--user-data-dir=C:\Users\Taro\AppData\Local\Google\Chrome\User Data");
            options.AddArguments(@"--profile-directory=プロファイル名");
            ChromeDriver driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), options);
            try
            {
                // Navigate to Url
                driver.Navigate().GoToUrl("https://www.google.co.jp/");

            }finally
            {
                Console.ReadKey();
                driver.Quit();
            }

Firefoxの場合

使いにくい。

            FirefoxOptions options = new FirefoxOptions();
            FirefoxProfile profile = new FirefoxProfile(@"Firefoxのプロファイル");
            options.Profile = profile;
            FirefoxDriver driver = new FirefoxDriver(options);
            
            try
            {
                // Navigate to Url
                driver.Navigate().GoToUrl("https://www.google.co.jp/");

            }finally
            {
                Console.ReadKey();
                driver.Quit();
            }

注意

ChromeもFirefoxも普段使っているプロファイルを想定している。

Chromeはコンソールでエラー表示が出るが、一応 動いてるっぽい。

Firefoxはブラウザーをいつものように使っていると、そのプロセスがロックファイルを使って、C#プログラムを起動できないセキュリティの高い仕様のようだ。プロセスを使っていない場合(ブラウザーを普段使いしていない場合)、プログラムは起動するがプロファイルが一時ファルダにコピーされるうえ、オーバーヘッドが大きく、やたら起動に時間がかかる。

解決方法は今の時点で見つからず。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?