2012-11-20 65 views
0
org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died. 
Build info: version: '2.25.0', revision: '17482', time: '2012-07-18 21:09:54' 
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_29' 
Driver info: driver.version: RemoteWebDriver 

這是當我試圖運行腳本時顯示的錯誤消息嗎? 情景:我的一個java文件具有登錄功能,第二個在登錄後創建了一個新帳戶 請注意。Selenium webdriver腳本中的UnreachableBrowserException

Login.java:

public class LoginPage 
{ 

    public static WebDriver driver; 

    public static final LoginPage login = new LoginPage(new FirefoxDriver()); 

    public LoginPage(WebDriver driver) 
    {  
     LoginPage.driver = driver; 
    } 

    public static void loginAs(String username, String password) 
    { 
     DesiredCapabilities ieCapabilities = DesiredCapabilities.firefox(); 

     ieCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); 

     Proxy proxy = new Proxy(); 

     proxy.setProxyAutoconfigUrl("http://www.config.barclays.co.uk:9000/"); 

     driver.close(); 

     ieCapabilities. setCapability(CapabilityType.PROXY, proxy); 

     FirefoxDriver driver = new FirefoxDriver(ieCapabilities); 

     driver.get("https://login.salesforce.com"); 

     driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS); 

     //Login to Salesforce Application 
     try 
     { 
      driver.findElement(By.id("username")).sendKeys(username); 

      driver.findElement(By.id("password")).sendKeys(password); 

      driver.findElement(By.id("Login")).click(); 

      driver.manage().timeouts().implicitlyWait(75, TimeUnit.SECONDS); 

     } 
     catch(Exception e1) 
     { 

      System.out.println(e1 +"Your login attempt has failed. The username or password may be incorrect, or your location or login time may be restricted. Please contact the administrator at your company for help."); 
     } 

    } 


    public static void main(String[] args) 
    { 
     login.loginAs("[email protected]", "Pa$$word"); 
    } 
} 

在那裏我試圖點擊我的銷售隊伍應用程序的機會標籤上的第二個文件: CreatOpportunity.java這些線是在我的主要論點

LoginPage.login.loginAs("username", "password"); 

LoginPage.login.driver.findElement(By.id("Opportunity_Tab")).click(); 

運行我的第二個文件允許我啓動我的應用程序,但沒有檢測到對話標籤上的點擊並引發上述錯誤

+0

只有在此腳本中出現此錯誤或任何腳本?如果對於每個腳本嘗試重新啓動您的所有瀏覽器實例 – vkrams

+0

我面臨的所有錯誤消息:Foreg:LoginPage.login.loginAs(「user name」,「Password」); 。LoginPage.driver.findElement(By.id( 「Opportunity_Tab」))點擊();然後我得到相同的錯誤,這裏loginPage幫助我登錄到應用程序,第二行是導航到應用程序的機會部分。請告知 – user1834699

+0

您能否粘貼您的代碼 – vkrams

回答

1

只需在登錄後輸入下面一行即可。

driver.switchTo.defaultContent(); 

嘗試使用以下代碼。如果調用退出()方法&嘗試再次啓動瀏覽器

public class LoginPage { 
    public static WebDriver driver; 

    public LoginPage() 
    {  
     DesiredCapabilities ieCapabilities = DesiredCapabilities.firefox(); 
     ieCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); 
     Proxy proxy = new Proxy(); 
     proxy.setProxyAutoconfigUrl("http://www.config.barclays.co.uk:9000/"); 
     ieCapabilities. setCapability(CapabilityType.PROXY, proxy); 
     LoginPage.driver = new FirefoxDriver(ieCapabilities); 
     driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS); 
    } 

    public static void loginAs(String username, String password) { 



     driver.get("https://login.salesforce.com"); 
     //Login to Salesforce Application 
     try 
      { 
      driver.findElement(By.id("username")).sendKeys(username); 
      driver.findElement(By.id("password")).sendKeys(password); 
      driver.findElement(By.id("Login")).click(); 
      driver.manage().timeouts().implicitlyWait(75, TimeUnit.SECONDS); 
      } 
     catch(Exception e1) { 

      System.out.println(e1 +"Your login attempt has failed. The username or password may be incorrect, or your location or login time may be restricted. Please contact the administrator at your company for help."); 
     } 
} 

    public static void main(String[] args) 
    { 
     LoginPage login = new LoginPage(); 
     login.loginAs("[email protected]", "Pa$$word"); 
     FileTwo.clickOpportunity(driver); 
    } 

} 

FileTwo傳送

public class FileTwo 
{ 
public static void clickOpportunity(WebDriver driver) 
throws Exception 
{ 
     driver.findElement(By.id("Opportunity_Tab")).click(); 
} 
} 
+0

HI Santosh,我可以使用單個java文件中的腳本單擊商機選項卡。我想從可重複使用的角度來看這裏是CreateLogin(這是一個fil),然後點擊Opportunity選項卡上的下一個函數/文件。所以當我試圖在另一個java文件中調用login()時。我收到上述錯誤信息...請提醒 – user1834699

0

硒拋出這個錯誤。解決方法是使用close()方法而不是quit()

相關問題