当我运行selenium脚本时,我正面临这个问题:(我在tomcat中运行此代码,这是在我遇到异常的时候,但在正常的日食中,这非常有效)
**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
任何人都可以帮助我解决此异常并为其提供解决方案
修改
代码:
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();