C# Selenium FireFox 接入阿布云

业务需要购买http隧道,发现阿布云还行,使用Selenium本来想要用谷歌浏览器的,但是发现不能直接设置账号,所以选用火狐。

按照官方JAVA示例的改编,其中WebDriver实例化不能直接添加FirefoxProfile,所以需要创建一个FirefoxOtions,在这里面添加Profile。

有一个要注意的是,需要引用System.Text.Encoding.CodePages的NuGet包,否则会找不到 Encoding(437) 错误。

参考这个:https://github.com/SeleniumHQ/selenium/issues/4816

代码如下:

            //必须添加这个代码,否则使用Profile报错
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
FirefoxProfile profile
= new FirefoxProfile(); // 使用代理 profile.SetPreference("network.proxy.type", 1); // 代理服务器配置 ProxyHost-http-dyn.abuyun.com ProxyPort-9020 profile.SetPreference("network.proxy.http", GlobalConf.ProxyHost); profile.SetPreference("network.proxy.http_port", GlobalConf.ProxyPort); profile.SetPreference("network.proxy.ssl", GlobalConf.ProxyHost); profile.SetPreference("network.proxy.ssl_port", GlobalConf.ProxyPort);
       //ProxyUser-通行证书 ProxyPass-通行密钥 profile.SetPreference(
"username", GlobalConf.ProxyUser); profile.SetPreference("password", GlobalConf.ProxyPass); // 所有协议公用一种代理配置,如果单独配置,这项设置为false profile.SetPreference("network.proxy.share_proxy_settings", true); // 对于localhost的不用代理,这里必须要配置,否则无法和webdriver通讯 profile.SetPreference("network.proxy.no_proxies_on", "localhost"); // 以代理方式启动firefox FirefoxOptions opt = new FirefoxOptions(); opt.Profile = profile; _firefoxDriver = new FirefoxDriver(GlobalConf.BrowserPath, opt);

 

转载于:https://www.cnblogs.com/dlvguo/p/10597739.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C# Selenium是一种用于自动化Web应用程序的工具。它使用Selenium WebDriver库来与浏览器进行交互,并可以进行各种Web自动化任务,如模拟用户操作、填写表单、点击按钮等。 在使用C# Selenium时,你需要引用一些核心库,包括Selenium.RC、Selenium.Support和Selenium.WebDriver。这些库提供了必要的功能和接口,使你能够编写C#代码来控制浏览器行为。 相比于Selenium RC,Selenium WebDriver的编程接口更加直观易懂,也更加简练。它提供了更多的内置方法和功能,使得编写自动化脚本更加方便。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [C# Selenium使用及诸多事项-I](https://blog.csdn.net/m0_37667916/article/details/104358336)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [C# 使用Selenium](https://blog.csdn.net/yangyong1250/article/details/128892399)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值