Pra*_*eek 48 c# selenium automation headless phantomjs
以下是我的代码:
case BrowserType.PhantomJS:
var service = PhantomJSDriverService.CreateDefaultService(Path.Combine(_rootPath, @"Packages\"));
var cookieFilePath=Path.Combine(_rootPath, @"Packages\cookie.txt");
if (!File.Exists(cookieFilePath))
File.Create(cookieFilePath);
var phantomjsoptions = new PhantomJSOptions();
driver = new PhantomJSDriver(service,phantomjsoptions);
var cookieJar = driver.Manage().Cookies;
driver.Navigate().GoToUrl(SeleniumConfiguration.Current.BaseURL);
cookieJar.AddCookie(new Cookie("x", "12345"));
return driver;
Run Code Online (Sandbox Code Playgroud)
基本上问题是我无法登录我的测试应用程序因为我收到错误说 -
"您的浏览器设置为阻止Cookie"
我已经尝试了一切,但我似乎无法得到解决方案.
我该怎么办?
请帮帮我.
如果遗漏了一些细节,请告诉我.
您必须等待页面加载,然后设置 cookie:
driver.Navigate().GoToUrl(SeleniumConfiguration.Current.BaseURL);
//Wait page loaded
cookieJar.AddCookie(new Cookie("x", "12345"));
Run Code Online (Sandbox Code Playgroud)
尝试这个解决方案:/sf/answers/2144589121/
driver.Navigate().GoToUrl(SeleniumConfiguration.Current.BaseURL);//some fake url
driver.Manage().Window.Maximize();
driver.SwitchTo().ActiveElement();
cookieJar.AddCookie(new Cookie("x", "12345"));
driver.Navigate().GoToUrl(SeleniumConfiguration.Current.BaseURL);//cookie exsist
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3707 次 |
| 最近记录: |