无法使用 selenium 脚本在 mozilla firefox 中写入 URL。即使eclipse也没有显示任何错误

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

尝试用selenium测试ikea主页script.Mozillafire fox打开但是地址栏输入url

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

    }

}

这是您问题的答案:

当您通过 Selenium-Java 绑定使用 Selenium 3.4.0、geckodriver v0.17.0、Mozilla 53.0 时,您拥有的不是 webdriver.firefox.marionette提及 webdriver.gecko.driverSystem.setProperty 如下:

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

休息你的代码工作正常:

修改后的代码:

    // 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");
    }

控制台输出:

Actual : IKEA
Expect : IKEA
Test Passed!

如果这回答了您的问题,请告诉我。