2016-09-22 60 views
0

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

这是我的主要活动。

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("[email protected]"); 
     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"); 

    } 

} 

但是,当脚本运行它开辟了不同的空白页和脚本失败

+0

尝试一次通过使用selelium代码清除缓存。 –

+0

我想怎么做? –

+0

driver.manage()。deleteAllCookies();你可以在导航到网址后写下这个 –

回答

0

找到了答案here。这是因为浏览器和Selenium库存兼容性问题。硒libs我使用支持Firefox版本不同的Firefox版本,并为12我不得不升级您的Selenium库。

相关问题