zoukankan      html  css  js  c++  java
  • 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);
  • 相关阅读:
    一个996程序员的自述:在公司眼里你就是一个工具
    我国为何如此重视编程教育?少儿编程会纳入基础教学吗?
    自学 Python 到什么程度能找到工作,1300+ 条招聘信息告诉你答案
    Book
    BFS
    Word写论文公式输入
    matlab保存超分辨率图
    [转载]有价值的Paper
    Latex作图
    微软企业库5.0学习笔记(七)存储容器的引用
  • 原文地址:https://www.cnblogs.com/dlvguo/p/10597739.html
Copyright © 2011-2022 走看看