2017-01-11 121 views
0

我使用Firefox浏览器版本50.1.0,Selenium 3.0.1,Java 1.8,TestNG和Eclipse。 我无法打开Firefox浏览器下面的代码:Firefox网络浏览器50.1.0不打开Selenium webdriver 3.0.1和Java 1.8

package test; 

import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.testng.annotations.BeforeTest; 

public class Login { 
@BeforeTest 
public void setup() { 
    WebDriver driver; 
    System.setProperty("webdriver.gecko.driver", "D:\\JavaPrograms\\geckodriver.exe"); 
    driver = new FirefoxDriver(); 
    driver.manage().window().maximize(); 
    driver.get("http://www.google.co.in"); 
} 
} 

但我得到以下异常:

org.openqa.selenium.WebDriverException:org.apache.http.conn.HttpHostConnectException :连接到本地主机:50091 [localhost/127.0.0.1]失败:连接被拒绝:连接 构建信息:版本:'unknown',修订:'1969d75',时间:'2016-10-18 09:43:45 -0700 ' at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:91) at org.openqa.selenium.remote.R emoteWebDriver.execute(RemoteWebDriver.java:601) 在org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:241) 在org.openqa.selenium.remote.RemoteWebDriver。(RemoteWebDriver.java:128) 在org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:259) at org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:247) at org.openqa.selenium.firefox.FirefoxDriver。( FirefoxDriver.java:242) at org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:238) at org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:127) at test.Login。设置(Login.java:12) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect。 NativeMethodAccessorImpl.invoke(来源不明) 在sun.reflect.DelegatingMethodAccessorImpl.invoke(来源不明) 在java.lang.reflect.Method.invoke(来源不明) 在org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java :104) 在org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:515) 在org.testng.internal.Invoker.invokeConfigurations(Invoker.java:217) 在org.testng.internal.Invoker.invokeConfigurations (Invoker.java:144) at org.testng.TestRunner.beforeRun(TestRunner.java:634) at org.testng.TestRunner.run(TestRunner.java:602) at org.testng.SuiteRunner.runTest(SuiteRunner .java:387) at org.testng.SuiteRunner.runSequen (SuiteRunner.java:382) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340) at org.testng.SuiteRunner.run(SuiteRunner.java:289) at org.testng.SuiteRunnerWorker.runSuite( SuiteRunnerWorker.java:52) 在org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) 在org.testng.TestNG.runSuitesSequentially(TestNG.java:1293) 在org.testng.TestNG.runSuitesLocally(TestNG的。的java:1218) 在org.testng.TestNG.runSuites(TestNG.java:1133) 在org.testng.TestNG.run(TestNG.java:1104) 在org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG。 java:132) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236) at org.testn g.remote.RemoteTestNG.main(RemoteTestNG.java:81) 引起:org.apache.http.conn.HttpHostConnectException:连接到本地主机:50091 [localhost/127.0.0.1]失败:连接被拒绝:在组织中连接 。 apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:158) at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353) at org.apache.http.impl。 execchain.MainClientExec.establishRoute(MainClientExec.java:380) at org.apache.http.impl.execchain.MainClientExec。执行(MainClientExec.java:236) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java: 88) 在org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) 在org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184) 在有机apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55) at org.openqa.selenium.remote。 internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:142) at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:88) 在org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:64) at org.openqa.selenium.remote。 HttpCommandExecutor.execute(HttpCommandExecutor.java:141) 在org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82) ...... 32多个

+2

请提供更多的信息。这意味着什么'firefox不开放'。你有豁免吗?也许它打开并马上终止? 提供堆栈跟踪信息 –

回答

0

有错误在您的网址 - 您正在使用

www.google.co.in 

需要变化 -

http://www.google.co.in 

由于httphttps在URL

+0

我仍然无法打开Firefox浏览器。 – mskumar

0

需要使用此代码:

@BeforeTest 
public void setup() { 
    System.setProperty("webdriver.gecko.driver", "D:\\JavaPrograms\\geckodriver.exe"); 
    WebDriver driver; 

    driver = new FirefoxDriver(); 
    driver.manage().window().maximize(); 
    driver.get("https://www.google.co.in"); 
} 
} 
相关问题