Browsermob不适用于Selenium webdriver


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();
     }
 }

我是硒和硒的新手。这是我的代码。我尝试执行此操作并得到错误The method setProxyPreferences(Proxy) is undefined for the type FirefoxProfile.如何解决这个问题?

您(通常(不需要手动配置FirefoxProfile设置。自述文件的"与硒一起使用"部分给出了如何将代理与硒一起使用的示例:

// 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();

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

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

driver = new FirefoxDriver(new FirefoxBinary(),profile,capabilities);

相关内容

  • 没有找到相关文章

最新更新