【问题标题】:Could not setup Firefox profile & proxy settings & authentication in Java无法在 Java 中设置 Firefox 配置文件和代理设置以及身份验证
【发布时间】:2012-11-23 06:32:15
【问题描述】:

尊敬的 Selenium Webdriver 大师,

我进行了以下 Firefox 配置文件设置更改,以尝试在使用 Selenium Webdriver 2 启动 Firefox 时拾取 FireBug:

public static void main(String[] args) 
{
    File fireBugFile = new File("C:/selenium-ide-1.9.0.xpi");
    FirefoxProfile firefoxProfile = new FirefoxProfile();
    firefoxProfile.addExtension(fireBugFile);
    firefoxProfile.setPreference("network.proxy.type", 1);
    firefoxProfile.setPreference("network.proxy.http", "proxyserver");
    firefoxProfile.setPreference("network.proxy.http_port", "80");
    firefoxProfile.setPreference("extensions.firebug.currentVersion", "1.9.0");

    String urlStrProxy = "http://www.example.com/",
    proxy = "proxyserver",
    port = "80",
    username = "jack",
    password = "XXXXXXX";

    Authenticator.setDefault(new SimpleAuthenticator(username,password));
    Properties systemProperties = System.getProperties();
    systemProperties.setProperty("http.proxyHost",proxy);
    systemProperties.setProperty("http.proxyPort","80");

    WebDriver driverMainPage = new FirefoxDriver(firefoxProfile);
}

public class SimpleAuthenticator extends Authenticator
{
   private String username, password;

   public SimpleAuthenticator(String username,String password)
   {
       this.username = username;
       this.password = password;
   }

   protected PasswordAuthentication getPasswordAuthentication()
   {
       return new PasswordAuthentication(username,password.toCharArray());
   }
}

还尝试在其他语句中包含代理设置和身份验证详细信息,以通过代理服务器而无需 当 Firefox 无法成功访问 www.abc.com 时,必须通过弹出屏幕手动输入:

还添加了“-Dhttp.proxyHost=proxyserver -Dhttp.proxyPort=80 -Dhttp.proxyUser=jack -Dhttp.proxyPassword=XXXXXXX”作为 JVM 选项。

我在 Windows XP 和 7 上运行 Java 7、Selenium 2.25.0、Netbeans 7.2。

没有一个搜索直接回答了这个问题。

非常感谢任何帮助。

提前致谢,

杰克

【问题讨论】:

    标签: java selenium selenium-webdriver


    【解决方案1】:

    我想端口号应该是整数

    firefoxProfile.setPreference("network.proxy.http_port", 80);

    为了处理要求输入用户名和密码的弹出窗口,您可以使用 autoit

    【讨论】:

    • 感谢 Abhi_Mishra 的回复。在 Selenium Webdriver 中使用 firefoxprofile 启动 Firefox 时无法加载 Firebug 的问题怎么办?谢谢,杰克
    【解决方案2】:

    根据提供的代码,提供了 selenium ide 而不是 firebug。看看吧

      File fireBugFile = new File("C:/selenium-ide-1.9.0.xpi");
    FirefoxProfile firefoxProfile = new FirefoxProfile();
    firefoxProfile.addExtension(fireBugFile);
    

    所以这可能是为什么火虫没有得到的问题.. 使用正确的版本 w.r.t firefox 版本提供火虫的正确位置。

    对于身份验证,以前我使用了以下一个,而没有考虑 firefox 配置文件。

    driver.get("http://UserName:Password@Example.com");
    

    并且还手动创建了 firefox 配置文件并为配置文件完成了身份验证。我在执行时调用了这个配置文件,这种方式在 firefox 的情况下也很有效。

    谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-06
      • 2013-06-01
      • 2017-08-12
      • 2016-02-18
      • 2019-07-15
      • 1970-01-01
      • 2010-10-17
      • 1970-01-01
      相关资源
      最近更新 更多