1

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);

    }

}

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks!! but after doing same modification getting error in console: Usage: C:\Users\orange\Downloads\geckodriver.exe [OPTIONS] C:\Users\orange\Downloads\geckodriver.exe: Unknown option --port=44135
Can you update your updated code block & the full error stack trace updated in the Question area please? Seems geckodriver is randomly trying to open port 44135 which is not available. Try restarting your system once. Thanks
Thanks!! after updating geckodriver and system restart it works

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.