SeleniumとjUnit4でWebページのテストをいくつか記述したいのですが、Firefoxで必要なURLを開く方法を理解できません。 System.setProperty(...)なしで私はException in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver.
を得ていて、ブラウザーは決して開かない。しかし、私がそれを実装すれば、ブラウザはデフォルトの開始 "新しいページ"でを開きますが、driver = new FirefoxDriver();
とさらにという行はを実行しません。以下は は私が達成しようとしているものの最も簡単なコードバージョンです:ブラウザは開きますが、Seleniumを使用してURLに移動しません
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Main {
static String URL = "http://www.google.com";
static WebDriver driver;
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
//Following code never executes
driver = new FirefoxDriver();
//I'm not sure if this is how I'm supposed to open URL, but I never had this code executed.
driver.get(URL);
driver.quit();
}
}
: これらのリンクは、適切geckodriverのインストールの問題を解決するために有用でした。 https://github.com/mozilla/geckodriver/releases
http://learn-automation.com/use-firefox-selenium-using-geckodriver-selenium-3/
を試してみてください、あなたがエラーを取得するか、またはしないこの
に代わり
firefox.exe
のgeckodriver.exe
パスを設定する必要がありますそれは単にサイトに行かないのですか?私はあなたが 'driver.quit()'が – mrfreesterと呼ばれる前に何が起こったかを見るためにこのコードをステップアップしたと仮定しています。単純なsout()の "new FirefoxDriver" –
私はNarendraの答えがあなたの問題だと信じています。 'geckodriver'をダウンロードして、' firefox.exe'ではなく、それを指し示す必要があります。基本的には、あなたのコードは 'firefox.exe'を実行していますが、それを運転する方法は分かりません。 – mrfreester