2016-09-22 20 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庫。

相關問題