How to start FireFoxDriver with Selenium 3.4.0 using Maven?

I am trying to use Selenium latest 3.4.0 on a maven project. I imported all Selenium jars using below dependencies: -

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.4.0</version>
</dependency>

      

The problem is I cant resolve any dependency in my project in Eclipse for below main method code: -

public class FirefoxTest {

    public static void main(String[] args) {
        FirefoxOptions options = new FirefoxOptions();
        options.setBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"); //This is the location where you have installed Firefox on your machine

        FirefoxDriver driver = new FirefoxDriver(options);
        driver.get("http://www.google.com");
    }
}

      

What am I missing? Eclipse cannot resolve FirefoxDriver type for any dependencies. Please, help.

+3


source to share


6 answers


To work with Selenium 3.4.0 and Mozilla Firefox 53.x, you need to download the latest geckodriver v0.16.1 from here . Save it in your machine and include the absolute path of the geckodriver in your code.

Make sure you update the pom.xml with the required dependency as follows:

<dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.4.0</version>
</dependency> 

      

It is recommended to use an interface WebDriver

rather than an implementation FirefoxDriver

.



Your code will look like this:

    System.out.println("Welcome to Maven World");
    System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
    WebDriver driver = new FirefoxDriver();       
    driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
    driver.navigate().to("http://www.google.com");

      

Provide the following commands to clean up previous dependencies, install new dependencies, and run the test:

>mvn clean
>mvn install
>mvn test 

      

+2


source


I faced the same problem and searched for a solution for a long time. Even if you change your code or dependencies, your code will still accept selenium mixers because of the wrong one, because your code is already built and the wrong selenium jars are assigned.

Follow these steps:



  • Right click on Maven dependencies from your Eclipse project and select Configure Maven Dependencies and drop Maven dependencies from your list and point your folder .m2

    where it is.
  • Once you define the folder .m2

    , open it, go to the repository and navigate to the org folder.
  • In this folder, delete all Selenium folders.
  • Go back to your file pom.xml

    , paste in Selenium 3.4.0 and remove all your 3.5.3 or other stuff (only over 3.4% of dependencies). Once again remove all other selenium dependencies.
  • Finally, save the file and create from the project section and you should be good to go now.
+1


source


I'm pretty sure the Firefox driver installation changed in version 3 of Selenium. Use this code:

System.setProperty("webdriver.firefox.driver","C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
WebDriver driver = new FirefoxDriver();

      

Please also read about it here

You will also find working test code here

Also check that you've included the correct import statements at the top of your class:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

      

0


source


Download Gecko driver: https://github.com/mozilla/geckodriver/releases

System.setProperty("webdriver.gecko.driver", "c:\\geckodriver.exe");
WebDriver driver = new MarionetteDriver();
driver.get("http://www.google.com");

      

0


source


I couldn't find the Maven coordinates for the gecko driver, which is now required for Selenium 3.4+. Someone has probably created a public repository, but it's still easy to download the drivers and add them directly to the project. To avoid static path issues (keeping these drivers in the project so things don't get interrupted later and the entire project can be submitted without complicated setup), it is best to place these drivers in your projects src/main/resources

.

Download drivers from: https://github.com/mozilla/geckodriver/releases (ARM, Linux, Mac and Windows downloads)

If you are running multiple OS, you might need to switch the OS based driver: How to programmatically determine the operating system in Java? p>

package com.kenmcwilliams.demo;

import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;

/**
 *
 * @author ken
 */
public class App {

    public static void main(String[] args){
        //if you're going to use more than one OS, you should make this switchable based on OS.
        Path path = FileSystems.getDefault().getPath("src/main/resources/geckodriver");
        System.setProperty("webdriver.gecko.driver",path.toString());
        WebDriver driver = new FirefoxDriver();
        //from here down is just a working example...
        driver.get("http://www.google.com");
        WebElement element = driver.findElement(By.name("q"));
        element.sendKeys("Cheese!");
        element.submit();
        System.out.println("Page title is: " + driver.getTitle());
        (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
            public Boolean apply(WebDriver d) {
                return d.getTitle().toLowerCase().startsWith("cheese!");
            }
        });
        System.out.println("Page title is: " + driver.getTitle());
        driver.quit();
    }
}

      

0


source


use the below dependency to load selenium.

<dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.4.0</version>
</dependency>

      

After downloading the dependencies. Run your build project.

This will solve your problem.

0


source







All Articles