Search code examples
javaseleniumtestingmozilla

Unable to write URL in mozilla firefox by using selenium script. Even eclipse doesn't show any error


Try to test the ikea home page by selenium script.Mozilla fire fox is open but url is entered in address bar.

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

public class ikeaautomation {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        // declaration and instantiation of objects/variables
        WebDriver driver ;
        System.setProperty("webdriver.firefox.marionette","C:\\Users\\orange\\Downloads\\geckodriver.exe");
        driver = new FirefoxDriver();
        String baseUrl = "http://ikea.in";
        String expectedTitle = "IKEA";
        String actualTitle = "";

        // launch Fire fox and direct it to the Base URL
        driver.get(baseUrl);

        // get the actual value of the title
        actualTitle = driver.getTitle();

        /*
         * compare the actual title of the page with the expected one and print
         * the result as "Passed" or "Failed"
         */
        if (actualTitle.contentEquals(expectedTitle)){
            System.out.println("Test Passed!");
        } else {
            System.out.println("Test Failed");
        }

        //close Fire fox
        driver.close();

        // exit the program explicitly
        System.exit(0);

    }

}

Solution

  • Here is the Answer to to your Question:

    While you work with Selenium 3.4.0, geckodriver v0.17.0, Mozilla 53.0 through Selenium-Java bindings, instead of webdriver.firefox.marionette you have to mention webdriver.gecko.driver through System.setProperty as below:

    System.setProperty("webdriver.gecko.driver","C:\\Users\\orange\\Downloads\\geckodriver.exe");
    

    Rest your code works fine:

    Modified Code:

        // launch Fire fox and direct it to the Base URL
        driver.get(baseUrl);
    
        // get the actual value of the title
        actualTitle = driver.getTitle();
        System.out.println("Actual : "+actualTitle);
        System.out.println("Expect : "+expectedTitle);
    
        /*
         * compare the actual title of the page with the expected one and print
         * the result as "Passed" or "Failed"
         */
        if (actualTitle.contentEquals(expectedTitle)){
            System.out.println("Test Passed!");
        } else {
            System.out.println("Test Failed");
        }
    

    Console Output:

    Actual : IKEA
    Expect : IKEA
    Test Passed!
    

    Let me know if that Answers your Question.