Add proxy to PhantomJSDriver (Selenium C#)

纵饮孤独 提交于 2019-12-19 11:39:49

问题


I'd like to listen to traffic generated by phantomjs selenium driver in c#. The below code does not work unfortunately!

PhantomJSOptions phoptions = new PhantomJSOptions();

phoptions.AddAdditionalCapability("proxy", "http://localhost:9999");

driver = new PhantomJSDriver(phoptions);

can anyone help me what's wrong with it!

Thanks in advance


回答1:


Proxy proxy = new Proxy();
proxy.HttpProxy = string.Format("127.0.0.1:9999");
var service = PhantomJSDriverService.CreateDefaultService();
service.ProxyType = "http";
service.Proxy = proxy.HttpProxy;
IWebDriver driver = new PhantomJSDriver(service);

Some quick testing showed this work for me.




回答2:


You can use the CapabilityType class to set the proxy capability. Here is a modified version of your code above:

PhantomJSOptions phoptions = new PhantomJSOptions();

phoptions.AddAdditionalCapability(CapabilityType.Proxy, "http://localhost:9999");

driver = new PhantomJSDriver(phoptions);

This worked for me. Arran's answer did not work for me. For some reason, my PhantomJSDriverService class did not have a ProxyType or Proxy member.



来源:https://stackoverflow.com/questions/18921099/add-proxy-to-phantomjsdriver-selenium-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!