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文件具有登录功能,第二个在登录后创建了一个新帐户 请建议。
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("me@example.com", "Pa$$word");
}
}
我试图点击Salesforce应用程序的Opportunity选项卡的第二个文件: CreatOpportunity.java这些行在我的主要参数
下LoginPage.login.loginAs("username", "password");
LoginPage.login.driver.findElement(By.id("Opportunity_Tab")).click();
运行我的第二个文件允许我启动我的应用程序,但是没有检测到Opprtunity选项卡上的点击并且抛出了上面提到的错误
答案 0 :(得分: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);
}
}
FileTwo传送
public class FileTwo
{
public static void clickOpportunity(WebDriver driver)
throws Exception
{
driver.findElement(By.id("Opportunity_Tab")).click();
}
}
答案 1 :(得分:0)
如果你调用quit()方法,那么Selenium就会抛出这个错误。尝试再次启动浏览器。解决方法是使用close()方法而不是quit()