Firefox打开多个空页面,而Selenium测试运行和测试无法识别元素

时间:2016-09-22 05:11:01

标签: java selenium firefox

我正在为我的网站编写Selenium测试脚本。 Firefox打开多个空页面,而Selenium测试运行和测试无法识别我的脚本中的元素。我正在使用 47.0.1 firefox selenium-server-standalone-3.0.0-beta3

这是我的主要活动。

public class Main {

    public static void main(String[] args) throws InterruptedException{

// Print the Execution Date
        GetExecutionDate getExDate = new GetExecutionDate();
        getExDate.getExecutionDate();

        MainFlow mainFl = new MainFlow();
        mainFl.mainFlow();
    }

}

这是我的MainFlow.java文件。

public class MainFlow {

    public void mainFlow() throws InterruptedException{

        System.setProperty("webdriver.firefox.marionette","D:\\My Work\\Setup\\JAR\\geckodriver.exe");

        // Initialize Firefox Profile
        ProfilesIni profile = new ProfilesIni();    
        FirefoxProfile myprofile = profile.getProfile("Myyy");  
        WebDriver driver = new FirefoxDriver(myprofile);


        //Puts an Implicit wait, Will wait for 25 seconds before throwing exception
        driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);

        //Launch Ayubo.lk site
        driver.navigate().to("my site");

        //Maximize the browser
        driver.manage().window().maximize();
        Thread.sleep(3000);

        driver.findElement(By.xpath("//div[@id='navbar-main']/ul/li[5]/a")).click();
        System.out.println("User clicked My Account button");

        driver.findElement(By.xpath("//div[@id='navbar-main']/ul/li[5]/ul/li/a")).click();
        System.out.println("User clicked Login button");
        Thread.sleep(3000);

        // Enter User name
        driver.findElement(By.name("email")).sendKeys("dd@hh.com");
        System.out.println("User enter username");

        // Enter Password
        driver.findElement(By.name("password")).sendKeys("12345");
        System.out.println("User enter password");
        Thread.sleep(3000);

        // Click Login Button
        driver.findElement(By.xpath("//form[@id='loginform']/div[8]/button")).click();
        System.out.println("User clicked Login button");
        Thread.sleep(5000);

        // Click Book now Button
        driver.findElement(By.xpath("//div[@id='navbar-main']/ul/li[2]/a/span")).click();
        System.out.println("User clicked Book now button");
        Thread.sleep(3000);

        // Click Book hotels button
        driver.findElement(By.xpath("//div[@id='navbar-main']/ul/li[2]/ul/li/a")).click();
        System.out.println("User clicked Book Hotels button");

    }

}

但是,当脚本运行时,它会打开不同的空页面并且脚本失败

1 个答案:

答案 0 :(得分:0)

找到答案here。这是因为浏览器和Selenium库的兼容性问题。 Selenium libs Im使用支持Firefox版本的不同firefox版本,而对于12我必须升级你的Selenium libs。