2012-11-23 43 views
0

亲爱的硒webdriver的大师,无法设置Firefox的配置和代理设置和认证Java中

我已经在尝试使用硒的webdriver 2启动Firefox时,提出了以下的Firefox配置文件设置更改皮卡萤火虫:

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上运行的Java 7,硒2.25.0,Netbeans的7.2 & 7.

无搜查都直接回答了这个问题。

任何援助将非常感激。

由于提前,

杰克

回答

1

我想端口号应在

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

以及处理弹出要求输入用户名和密码,您的整可以使用autoit

+0

感谢Abhi_Mishra为您的回应。在Selenium Webdriver中使用firefoxprofile启动Firefox时无法加载Firebug的问题如何?谢谢,杰克 –

0

根据提供的代码,提供了硒代替萤火虫。看它

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:[email protected]"); 

并且还为配置文件手动创建了firefox配置文件并完成了身份验证。我在执行过程中调用了这个配置文件,这种方式在firefox的情况下也能很好地工作。

谢谢