Selenium chromedriver没有启动

时间:2017-04-17 09:22:44

标签: selenium selenium-webdriver

org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:18562 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect
Build info: version: '3.3.1', revision: '5234b32', time: '2017-03-10 09:04:52 -0800'
System info: host: 'MAC-SANU', ip: '192.168.0.71', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_60'
Driver info: driver.version: RemoteWebDriver

我的剧本:

System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.chrome(); 
ChromeOptions options = new ChromeOptions(); 
options.addArguments("test-type"); capabilities.setCapability("chrome.binary","D:\\SeleniumWork‌​space\\NVState\\chro‌​medriver.exe"); 
capabilities.setCapability(ChromeOptions.CAPABILITY, options); 
driver = new ChromeDriver(capabilities);

1 个答案:

答案 0 :(得分:1)

您需要按照以下步骤进行逐步合并:

  1. 提供chromedriver的绝对路径:
  2. System.setProperty("webdriver.chrome.driver", "C:\\your_directory\\chromedriver.exe");

    1. 获取ChromeOptions类的帮助:
    2. ChromeOptions options = new ChromeOptions();

      1. 添加选项:
      2. options.addArguments("test-type");

        1. 借助DesiredCapabilities类:
        2. DesiredCapabilities capabilities = DesiredCapabilities.chrome();

          1. 在功能中添加选项:
          2. capabilities.setCapability(ChromeOptions.CAPABILITY, options);

            1. 使用ChromeDriver初始化WebDriver实例以及功能:
            2. WebDriver driver = new ChromeDriver(capabilities);

              1. 打开网址:
              2. driver.get("http:\\gmail.com");

                如果这有助于您,请告诉我。