有朋友给我这样一段代码:
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”));
基本问题是无法登录测试应用程序,因为得到一个错误提示 “你的浏览器设置为阻止cookie”,尝试过很多办法,但无法得到解决方案 ....
实际上以下步骤即可解决:
1)在firefox或chrome浏览器中创建用户配置文件。 2)通过转到浏览器设置选项确认启用了“接受cookie”选项。 3)通过硒加载您的配置文件。
这样做将确保启用cookie选项为ON,并且您的会话也将保存在浏览器缓存中。
对于chrome
System.setProperty(“webdriver.chrome.driver”,“browser / chromedriverlinux”);
ChromeOptions选项=新的ChromeOptions();
options.addArguments(“ - user-data-dir = / home / rohit / .config / google-chrome / Profile 1”);
options.addArguments( “ - 启动最大化”);
WebDriver驱动程序=新的ChromeDriver(选项);
对于Firefox
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffprofile = profile.getProfile(“ROHIT”);
WebDriver driver = new FirefoxDriver(ffprofile);
文章部分资料来源:https://jlcaqx.weebly.com/ 如需转载请注明
相关推荐
在c# 中应用selenium的一些写法
Building a flexible and extensible framework around Selenium.pdf 博文链接:https://numenzq.iteye.com/blog/187408
录制工具selenium_ide_button-1.2.0-fx.xpi
C# selenium用到的关键字汇总,
Selenium WebDriver 3.14.0 本来需要.net45 我改为.net2.0 希望喜欢的人需要。 dll 反编译,嵌入程序内。无需调用那个讨厌的dll。 绝对不骗人,骗人是小狗。架构复杂修改麻烦,各位体谅
Selenium 官方中文文档
自动化测试:Selenium webdriver学习笔记C#版
One of test automation tools is Selenium. It is widely used around the world as a tool for automating test for web application. In this book we use Selenium WebDriver to perform automatic operation of...
Selenium官方中文文档
C#操作Selenium自动化测试,采集数据实例源码。压缩包内有所需的资源,代码内有详细注释。可用于爬虫,采集数据,效率低,通过率高。
1.selenium中文API 2.笔记
本文主要介绍了C#使用Selenium+PhantomJS抓取数据的方法步骤,具有很好的参考价值,下面跟着小编一起来看下吧
该资源中包含的chromedriver匹配的为84、85版本的谷歌浏览器,其他的nuget包也匹配改版本的chromedriver,使用的话,需要匹配对应版本的谷歌浏览器。
163邮箱的访问基于urllib进行爬取时需要自己从网页拿取cookie,但这个cookie是动态的,如果想实时对邮箱进行检查是否有新邮件,...上一篇里面的参考文献中提供了另一种方法,基于selenium进行自动登录,爬取cookie。
爬虫+selenium自动化+C#+采集器+strong-web-crawler-master。
生成的测试脚本可以用Selenium Core手工执行,也能基于Selenium RC放入Java,C#,Ruby的单元测试用例中自动运行。 3. 测试用例调用实际的浏览器(如IE、FireFox)来执行测试。 和有些开源方案自行实现Web解释引擎...
你可以直接在SeleniumIDE 中执行html 格式的脚本。你机器上的FireFox 将会执行 Selenium 脚本。 Selenium 生成的Html 格式的脚本,是Selenium 使用Html 的语言元素自己开发的一套 脚本语言。 如果你要执行其他语言...
selenium2.0中文帮助文档.pdf