嘗試使用 Selenium WebDriver 4.10 和 C# (.NET Framework 4.5.2) 使用以下代碼構建測驗時,我收到一個彈出視窗,要求選擇組態檔。據我了解,下面的代碼已經指定要使用的組態檔:
string strEdgeProfilePath = @"C:\\Users\\" Environment.UserName @"\\AppData\\Local\\Microsoft\\Edge\\User Data";
string strDefautProfilePath = strEdgeProfilePath @"\\Default";
string strSeleniumProfilePath = strEdgeProfilePath @"\\Selenium"; // <---- I have deleted this folder and copied the contents of the "Default" folder to no avail.
using (var service = EdgeDriverService.CreateDefaultService(@"C:\Temp\Selenium\Edge")) {
service.UseVerboseLogging = true;
EdgeOptions edgeOptions = new EdgeOptions();
edgeOptions.AddArgument("--user-data-dir=" strSeleniumProfilePath);
edgeOptions.AddArgument("--profile-directory=Selenium");
driver = new EdgeDriver(@"C:\Temp\Selenium\Edge", edgeOptions); // <----- msedgeserve.exe located here
}
即使我選擇了組態檔,Microsoft Edge 也不會繼續并且測驗超時。
我可以做些什么來阻止組態檔選擇并讓測驗運行?
uj5u.com熱心網友回復:
您的代碼中存在一些問題:
- 你不需要使用雙反斜杠,反斜杠就足夠了。
- 的值
--user-data-dir不正確。使用strEdgeProfilePath它就足夠了。
所以正確的代碼應該是這樣的:
string strEdgeProfilePath = @"C:\Users\" Environment.UserName @"\AppData\Local\Microsoft\Edge\User Data";
...
\\Here you set the path of the profile ending with User Data not the profile folder
edgeOptions.AddArgument("--user-data-dir=" strEdgeProfilePath);
\\Here you specify the actual profile folder
\\If it is Default profile, no need to use this line of code
edgeOptions.AddArgument("--profile-directory=Selenium");
此外,為避免運行 Edge 行程錯誤,您需要按照此答案中的備份步驟進行操作。請使用備份檔案夾而不是代碼中的原始檔案夾。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/436839.html
上一篇:Python,Selenium:如何指定哪些站點可以加載影像?
下一篇:org.openqa.selenium.StaleElementReferenceException:元素未附加到頁面檔案
