Firefox Web浏览器50.1.0未打开Selenium webdriver 3.0.1和Java 1.8

时间:2017-01-11 12:20:54

标签: java selenium firefox

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

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:连接到localhost:50091 [localhost / 127.0.0.1]失败:连接被拒绝:连接   建立信息:版本:'未知',修订版:' 1969d75',时间:' 2016-10-18 09:43:45 -0700'   在org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:91)       在org.openqa.selenium.remote.RemoteWebDriver.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)       在org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:247)       在org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:242)       在org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:238)       在org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:127)       at test.Login.setup(Login.java:12)       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)       at java.lang.reflect.Method.invoke(Unknown Source)       at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:104)       at 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)       在org.testng.TestRunner.run(TestRunner.java:602)       在org.testng.SuiteRunner.runTest(SuiteRunner.java:387)       at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:382)       在org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)       在org.testng.SuiteRunner.run(SuiteRunner.java:289)       在org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)       在org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)       at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293)       at org.testng.TestNG.runSuitesLocally(TestNG.java:1218)       在org.testng.TestNG.runSuites(TestNG.java:1133)       在org.testng.TestNG.run(TestNG.java:1104)       at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)       at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)       在org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)   引起:org.apache.http.conn.HttpHostConnectException:连接到localhost:50091 [localhost / 127.0.0.1]失败:连接被拒绝:连接       at org.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)       在org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)       在org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)       在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)       在org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)       在org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)       在org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:142)       在org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:88)       在org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:108)       在org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:64)       在org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)       在org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)       ......还有32个

2 个答案:

答案 0 :(得分:0)

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

www.google.co.in

需要改变 -

http://www.google.co.in

网址

中需要httphttps

答案 1 :(得分: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");
}
}