--user-data-dir
問題:
硒用戶在載入Chrome設定檔時經常會遇到懸掛式--user-data-dir
和--profile-directory
。 瀏覽器通常會凍結長達60秒鐘,然後才能破壞自動化。
解決方案:>避免預設設定檔
>關鍵是避免預設的chrome設定檔。 預設設定檔中的副檔名,書籤和瀏覽歷史記錄可能與測試相衝突,從而導致錯誤。 相反,創建並使用專用的設定檔。>
建立自訂鉻設定檔:>
chrome://settings/
有自訂設定檔後,請使用指定其位置:
。 ChromeOptions
應該指向您的Chromedriver執行檔。
ChromeOptions options = new ChromeOptions(); options.AddArgument($"--user-data-dir={profileDirectoryPath}"); // Use string interpolation for clarity options.AddArgument("--disable-extensions"); ChromeDriver driver = new ChromeDriver(@"pathtoexe", options);
完整範例:{profileDirectoryPath}
pathtoexe
>成功的測驗執行:
透過使用這種自訂設定檔方法,Chrome應該在不懸掛的情況下啟動Chrome,從而使您的硒測試可以平穩運行。 記得用實際目錄路徑取代佔位符路徑。
以上是如何避免使用`-user-data-dir`'selenium chrome crome croment危險問題?的詳細內容。更多資訊請關注PHP中文網其他相關文章!