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文件有登录功能,第二个有登录后创建一个新帐户请指教。

登录.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("me@example.com", "Pa$$word"); 
    }
}

我试图单击销售队伍应用程序的机会选项卡的第二个文件:CreatOpportunity.java 这些行在我的主要论点下

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

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

运行我的第二个文件允许我启动我的应用程序,但没有检测到 Opprtunity 选项卡上的点击,并抛出上述错误

4

2 回答 2

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("me@example.com", "Pa$$word"); 
        FileTwo.clickOpportunity(driver);
    }

}

文件二

public class FileTwo
{
 public static void clickOpportunity(WebDriver driver)
 throws Exception
 {
      driver.findElement(By.id("Opportunity_Tab")).click();
 }
}
于 2012-11-20T09:41:19.713 回答
0

如果您调用 quit() 方法并尝试再次启动浏览器,Selenium 会抛出此错误。解决方法是使用 close() 方法而不是 quit()

于 2013-05-02T06:15:04.050 回答