1

I am facing this issue when i run the selenium script: (I am running this code in tomcat and this is when I face the exception but in normal eclipse this works perfectly well)

**org.openqa.selenium.WebDriverException: org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(/opt/firefox/firefox-bin) on port 7055; process output follows:** 
Error: cannot open display: www.displayName.com:0.0
�
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.21-1.32.6.amzn1.x86_64', java.version: '1.7.0_05'
Driver info: driver.version: firefox
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.21-1.32.6.amzn1.x86_64', java.version: '1.7.0_05'
Driver info: driver.version: firefox
    at org.openqa.selenium.firefox.internal.ExtensionConnectionFactory.connectTo(ExtensionConnectionFactory.java:46)
    at org.openqa.selenium.firefox.FirefoxDriver.connectTo(FirefoxDriver.java:127)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:117)
    at com.domain.myproject.server.MyServlet.doFilter(CrawlServlet.java:120)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at com.ensarm.wikirealty.server.service.CacheControllerFilter.doFilter(CacheControllerFilter.java:46)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:67)
    at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:122)
    at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:110)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)
Caused by: org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(/opt/firefox/firefox-bin) on port 7055; process output follows: 
Error: cannot open display: www.wikirealty.com:0.0
�
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.21-1.32.6.amzn1.x86_64', java.version: '1.7.0_05'
Driver info: driver.version: firefox
    at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.connectToBrowser(NewProfileExtensionConnection.java:60)
    at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.<init>(NewProfileExtensionConnection.java:49)
    at org.openqa.selenium.firefox.internal.ExtensionConnectionFactory.connectTo(ExtensionConnectionFactory.java:44)
    ... 27 more
Caused by: org.openqa.selenium.firefox.NotConnectedException: Failed to start up socket within 45000
    at org.openqa.selenium.firefox.internal.AbstractExtensionConnection.connectToBrowser(AbstractExtensionConnection.java:143)
    at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.connectToBrowser(NewProfileExtensionConnection.java:58)
    ... 29 more

Please can anybody help me with this exception and give solution for it

EDIT

Code:

String url = "google.com";
WebDriver driver = new FirefoxDriver();
String str =""; 
driver.get(url); 
driver.wait(10000);
str = driver.getPageSource();
System.out.println(str); 
driver.close(); 
Mahesh More
  • 919
  • 2
  • 8
  • 20
  • could you show us what you are trying to do? – Tarken Aug 23 '12 at 13:46
  • actually there is servlet of mine which will open the specified url in the firefox driver and then i will dome some processing out there. When I run my code on my local machine it works fine, but when i run it on aws ec2 intance its throwing this excpetion. – Mahesh More Aug 23 '12 at 13:56
  • 2
    is your instance headless? if yes than that is the problem. ff needs a window – Tarken Aug 23 '12 at 14:04
  • 1
    http://www.alittlemadness.com/2008/03/05/running-selenium-headless/ might be an idea – Tarken Aug 23 '12 at 14:05
  • i did all the changes mentioned in the link but facing this exception : org.openqa.selenium.WebDriverException: org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(/opt/firefox/firefox-bin) on port 7055; process output follows: �* e = [Exception... "Component returned failure code: 0x80570016 (NS_ERROR_XPC_GS_RETURNED_FAILURE) [nsIJSCID.getService]" nsresult: "0x80570016 (NS_ERROR_XPC_GS_RETURNED_FAILURE)" location: "JS frame :: chrome://browser/content/utilityOverlay.js :: getShellService :: line 339" data: no] – Mahesh More Aug 24 '12 at 13:30
  • Are you using the newest Selenium Version? Is your problem similar to [this](http://www.seleniumwebdriver.com/google-selenium-webdriver/failed-to-connect-to-binary-firefoxbinary/)? – Tarken Aug 27 '12 at 06:38
  • @tarken : my source code goes like this : String url = "http://www.google.com"; System.out.println("Page name : " + pageName); WebDriver driver = new FirefoxDriver(); String str =""; synchronized(driver) { driver.get(pageName); driver.wait(10000); str = driver.getPageSource(); System.out.println(str); driver.close(); } *** but when the instance for this is getting created I am getting the exception I am using X11:1 for display. – Mahesh More Aug 27 '12 at 13:47
  • please edit your code to your answer. Why are you using synchronized? pageName is not initialized. you should use driver.quit to close your browser see the api for that. Which Selenium Version are you using? – Tarken Aug 28 '12 at 06:30
  • @tarken : code goes like this :: String url = "http://www.google.com"; WebDriver driver = new FirefoxDriver(); String str =""; driver.get(url); driver.wait(10000); str = driver.getPageSource(); System.out.println(str); driver.close(); ***** and this code is been ran o the headles... – Mahesh More Aug 28 '12 at 06:53
  • 1
    Some more links for headless problems [Link1](http://www.alittlemadness.com/2008/03/05/running-selenium-headless/) [Link2](http://www.seleniumtests.com/2012/04/headless-tests-with-firefox-webdriver.html) – Tarken Aug 28 '12 at 07:49
  • @Tarken : hey that links helped at least its now showing some different exception. Now when i did the modification as mentioned in link 2 aused the same code it is now going in the non-stoppable wait... How to go abt it? – Mahesh More Aug 28 '12 at 10:57
  • what do you mean by code is now going in the non-stoppable wait... How about it? – Tarken Aug 28 '12 at 11:00
  • means when the it is about to create the driver instance it take a hug amount of time and finally i have to stop the script and the code doesnt move forward beyond driver instance creation... – Mahesh More Aug 28 '12 at 11:19
  • @Tarken : i m getting this exception after that long wait :: org.openqa.selenium.WebDriverException: Unable to bind to locking port 7054 within 45000 ms – Mahesh More Aug 28 '12 at 14:07

2 Answers2

3

After lot of googling and going through Tarken link the final solution is:

  1. Add the xvfb on the headless server
  2. make set the xvfb property to firefox profile while creating its instance.
  3. have a proper combination of your jars and please do remove the redundant jars
Mahesh More
  • 919
  • 2
  • 8
  • 20
2

If your instance is headless than that is the problem. Firefox needs a window.

Some links for headless problems:

Tarken
  • 2,112
  • 2
  • 23
  • 42