0

親愛なる Selenium Webdriver 達人へ

Selenium Webdriver 2 を使用して Firefox を起動するときに FireBug を検出するために、次の 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 にアクセスしているときに、ポップアップ画面から手動で入力することなく、プロキシ サーバーを通過するための追加のステートメントを含むプロキシ設定と認証の詳細を含めようとしています。

また、JVM オプションとして「-Dhttp.proxyHost=proxyserver -Dhttp.proxyPort=80 -Dhttp.proxyUser=jack -Dhttp.proxyPassword=XXXXXXX」を追加しました。

Windows XPおよび7でJava 7、Selenium 2.25.0、Netbeans 7.2を実行しています。

この質問に直接答えた検索はありません。

どんな援助でも大歓迎です。

前もって感謝します、

ジャック

4

2 に答える 2

1

ポート番号は整数である必要があると思います

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

また、ユーザー名とパスワードを要求するポップアップを処理するには、autoitを使用できます。

于 2012-11-23T06:49:08.070 に答える
0

提供されたコードに従って、firebug の代わりに selenium ide が提供されます。見て

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

したがって、これが問題になる可能性があります。これは、火災バグが発生しない理由です.. 火災バグの正しい場所と、Firefox バージョンに関する正しいバージョンを提供してください。

認証のために、以前はFirefoxプロファイルを考えずに以下を使用していました。

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

また、firefox プロファイルを手動で作成し、プロファイルの認証を行いました。私は実行時にこのプロファイルを呼び出しました。この方法は、Firefox の場合にも非常にうまく機能します。

ありがとう

于 2015-12-31T11:38:24.093 に答える