小编Pra*_*eek的帖子

如何在phantomjsdriver selenium c#中启用cookie?

以下是我的代码:

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"

我已经尝试了一切,但我似乎无法得到解决方案.
我该怎么办?
请帮帮我.
如果遗漏了一些细节,请告诉我.

c# selenium automation headless phantomjs

48
推荐指数
1
解决办法
3707
查看次数

标签 统计

automation ×1

c# ×1

headless ×1

phantomjs ×1

selenium ×1