Toutes les réponses ci-dessus sont correctes, ce qui suit est la petite plongée dans le problème et la solution.
Le constructeur du pilote en sélénium par exemple
WebDriver driver = new ChromeDriver();
recherches pour le fichier exécutable du pilote, dans ce cas, les recherches du pilote de chrome pour exécutable pilote de chrome, dans le cas où le service ne parvient pas à trouver l'exécutable l'exception est levée
c'est là l'exception vient de (note la méthode de l'état de contrôle)
/**
*
* @param exeName Name of the executable file to look for in PATH
* @param exeProperty Name of a system property that specifies the path to the executable file
* @param exeDocs The link to the driver documentation page
* @param exeDownload The link to the driver download page
*
* @return The driver executable as a {@link File} object
* @throws IllegalStateException If the executable not found or cannot be executed
*/
protected static File findExecutable(
String exeName,
String exeProperty,
String exeDocs,
String exeDownload) {
String defaultPath = new ExecutableFinder().find(exeName);
String exePath = System.getProperty(exeProperty, defaultPath);
checkState(exePath != null,
"The path to the driver executable must be set by the %s system property;"
+ " for more information, see %s. "
+ "The latest version can be downloaded from %s",
exeProperty, exeDocs, exeDownload);
File exe = new File(exePath);
checkExecutable(exe);
return exe;
}
ce qui suit est la vérification sta Procédé te qui lève l'exception
/**
* Ensures the truth of an expression involving the state of the calling instance, but not
* involving any parameters to the calling method.
*
* <p>See {@link #checkState(boolean, String, Object...)} for details.
*/
public static void checkState(
boolean b,
@Nullable String errorMessageTemplate,
@Nullable Object p1,
@Nullable Object p2,
@Nullable Object p3) {
if (!b) {
throw new IllegalStateException(format(errorMessageTemplate, p1, p2, p3));
}
}
SOLUTION: définir la propriété système avant de créer l'objet pilote comme suit
System.setProperty("webdriver.gecko.driver", "path/to/chromedriver.exe");
WebDriver driver = new ChromeDriver();
suivant est le fragment de code (pour le chrome et firefox) lorsque la recherche de services de driver pour l'exécutable du pilote:
Chrome:
@Override
protected File findDefaultExecutable() {
return findExecutable("chromedriver", CHROME_DRIVER_EXE_PROPERTY,
"https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver",
"http://chromedriver.storage.googleapis.com/index.html");
}
FireFox:
@Override
protected File findDefaultExecutable() {
return findExecutable(
"geckodriver", GECKO_DRIVER_EXE_PROPERTY,
"https://github.com/mozilla/geckodriver",
"https://github.com/mozilla/geckodriver/releases");
}
où CHROME_DRIVER_EXE_PROPERTY = "webdriver.chrome.driver" et GECKO_DRIVER_EXE_PROPERTY = "webdriver.gecko.driver"
similaire est le cas pour les autres navigateurs, à la suite est l'instantané de la liste de l'implémentation de navigateur disponible
Il est utile de savoir si vous avez téléchargé le pilote chrome sélénium à l'adresse http://code.google.com/p/chromedriver/downloads/list et si vous l'avez ajouté à la bibliothèque dans eclipse sous "Ajouter des fichiers externes". avant d'exécuter votre code selenium-java. – Hemanth