Oreliya Fernando Oreliya Fernando - 16 days ago 13
Java Question

UnreachableBrowserException in PhantomJS

I'm using Selenium Webdriver and PhantomJS version 2.0.0

I'm getting "org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died." error when I execute my code.

Below is a sample code of my class.

rateMaintenancePg = createRatePg.closeGuideRatesUI();
Sleep(6);
getscreenshot();
Sleep(6);
System.out.println("Closed Create Rate UI.");
Sleep(3);
driver.switchTo().defaultContent();
driver.switchTo().frame("main");
driver.switchTo().frame("frmTabmenu_spnTabMenus_0");
Sleep(3);
System.out.println("Go to iframe frmTabmenu_spnTabMenus_0");
homePg = rateMaintenancePg.closeRateMaintenanceUI();
Sleep(3);
getscreenshot();
Sleep(3);
driver.navigate().refresh();
Sleep(4);


I'm getting this error in this line:

driver.switchTo().defaultContent();

Answer

This happens when you open more than one PhantomJs driver objects. The solution is you have to kill all the running PhantomJs drivers in your machine before start the test suite.