メインメニューを開く

.NET版のSeleniumでCookieなどユーザーデータの保存先を指定する

Seleniumを起動しなおしてもキャッシュやCookieを消さずに使いまわしたい。

Chrome Driver編集

Chrome Driverだと起動するたびに完全な新規セッションになるようだ。

Visual Studio for Macで動かしているで「/tmp」を指定してみた。 「/tmp/c1」ディレクトリが生成されていれば大丈夫っぽい。

    // user-data-dirは絶対パスで指定する。相対パスだとダメ。
    var options = new ChromeOptions();
    options.AddArgument(@"--user-data-dir=/tmp/c1");

    var chrome = new ChromeDriver(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), options);

関連項目編集