首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Browsermob不支持selenium webdriver

Browsermob不支持selenium webdriver
EN

Stack Overflow用户
提问于 2015-02-09 15:44:25
回答 2查看 1.4K关注 0票数 0
代码语言:javascript
复制
public class Test_One 
{
 public static void main(String[] args) throws Exception {
     ProxyServer server = new ProxyServer(8105);
     server.start();
     server.setCaptureHeaders(true);

     server.setCaptureContent(true);
     server.newHar("test");
     DesiredCapabilities capabilities = new DesiredCapabilities();
     Proxy proxy = server.seleniumProxy();
     FirefoxProfile profile = new FirefoxProfile();
     profile.setAcceptUntrustedCertificates(true);
     profile.setAssumeUntrustedCertificateIssuer(true);
     profile.setPreference("network.proxy.http", "localhost");
     profile.setPreference("network.proxy.http_port", 8105);
     profile.setPreference("network.proxy.ssl", "localhost");
     profile.setPreference("network.proxy.ssl_port", 8105);
     profile.setPreference("network.proxy.type", 1);
     profile.setPreference("network.proxy.no_proxies_on", "");
     //profile.setProxyPreferences(proxy);
     profile.setPreference(key, value)
     capabilities.setCapability(FirefoxDriver.PROFILE,profile);
     capabilities.setCapability(CapabilityType.PROXY, proxy);
     WebDriver driver = new FirefoxDriver(capabilities);
     driver.get("http://www.google.com");
     Har har1 = server.getHar();
     }
 }

我刚接触硒和broswermob。这是我的代码。当我尝试执行此命令时,得到错误The method setProxyPreferences(Proxy) is undefined for the type FirefoxProfile。如何解决这个问题?

EN

回答 2

Stack Overflow用户

发布于 2015-02-11 05:53:18

您(通常)不需要手动配置FirefoxProfile设置。自述文件的Using With Selenium部分提供了如何在Selenium中使用代理的示例:

代码语言:javascript
复制
// start the proxy
ProxyServer server = new ProxyServer(4444);
server.start();

// get the Selenium proxy object
Proxy proxy = server.seleniumProxy();

// configure it as a desired capability
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, proxy);

// start the browser up
WebDriver driver = new FirefoxDriver(capabilities);

// create a new HAR with the label "yahoo.com"
server.newHar("yahoo.com");

// open yahoo.com
driver.get("http://yahoo.com");

// get the HAR data
Har har = server.getHar();

如果这不起作用,可能是你的火狐和/或Selenium和/或BrowserMob代理的特定版本有问题。您使用的是什么版本?带有确切错误消息的堆栈跟踪也会有所帮助。

票数 0
EN

Stack Overflow用户

发布于 2015-08-18 22:27:22

尝试从功能中删除配置文件,并将其直接传递给FirefoxDriver:

代码语言:javascript
复制
driver = new FirefoxDriver(new FirefoxBinary(),profile,capabilities);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28404986

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档