2

私は Selenium FirefoxDriver を使用していますが、何をするにしても、デフォルトのユーザー プロファイル (アドオンなど) から開始したいと考えてます。私はその部分を機能させました。また、プログラムの制御に役立つ簡単な GUI も作成しました。この GUI には、ドライバーを開始するボタンと、 quit()を呼び出す別のボタンがあります。

問題:

  1. [スタート] -> [正常に動作します] をクリックします。FirefoxDriver には、すべてのアドオン、ブックマーク、...
  2. 閉じるをクリックします->正常に動作します。ブラウザはきれいに閉じます(私が知る限り)。
  3. もう一度 [開始] をクリックします -> ブラウザが起動しますが、プロファイルは空白です。アドオンなし、何もありません

これが、ドライバーをインスタンス化する方法です。何が問題を引き起こしているのかわかりません。助けてください!

public static final FirefoxProfile FIREFOX_PROFILE = new ProfilesIni().getProfile("default");
public static final FirefoxBinary FIREFOX_BIN = new FirefoxBinary(new File("..."));

public static FirefoxDriver getNewFirefoxInstance() {
    FirefoxDriver firefox = new FirefoxDriver(FIREFOX_BIN, FIREFOX_PROFILE);
    firefox.manage().timeouts().implicitlyWait(8, TimeUnit.SECONDS);
    return firefox;
}

private FirefoxDriver firefox = null;

JButton newFirefox = new JButton("Start FF");
newFirefox.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent arg0) {
        if (firefox == null){
            firefox = getNewFirefoxInstance();
        }
    }
});

JButton closeFirefox = new JButton("Close FF");
closeFirefox.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent arg0) {
        if (firefox != null){
            firefox.quit();
            firefox = null;
        }
    }
});
4

0 に答える 0