簡體   English   中英

硒連接拒絕錯誤

[英]Selenium connection refused error

我正在嘗試建立一個簡單的Selenium項目,但無法正確進行初始設置。 我當前的代碼是:

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;

public class webdriverdemo {

    public static void main(String[] args) {

        System.setProperty("webdriver.gecko.driver", "geckodriver");
        FirefoxOptions firefoxOptions = new FirefoxOptions();
        firefoxOptions.setCapability("marionette", true);
        WebDriver driver = new FirefoxDriver(firefoxOptions);
        driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);

        driver.navigate().to("http://www.calculator.net/");

        driver.manage().window().maximize();

        driver.findElement(By.xpath(".//*[@id = 'menu']/div[3]/a")).click();

        driver.findElement(By.xpath(".//*[@id = 'menu']/div[4]/div[3]/a")).click();

        driver.findElement(By.id("cpar1")).sendKeys("10");

        driver.findElement(By.id("cpar2")).sendKeys("50");

        driver.findElement(By.xpath(".//*[@id = 'content']/table/tbody/tr[2]/td/input[2]")).click();

        String result = driver.findElement(By.xpath(".//*[@id = 'content']/p[2]/font/b")).getText();

        System.out.println("The result is " + result);

        driver.close();

    }

}

我得到的錯誤是:

1510139780110   geckodriver INFO    geckodriver 0.19.1
1510139780119   geckodriver INFO    Listening on 127.0.0.1:3448
1510139781051   mozrunner::runner   INFO    Running command: "/usr/lib64/firefox/firefox" "-marionette" "-profile" "/tmp/rust_mozprofile.KnF05xRcbAZX"
1510139784365   Marionette  INFO    Listening on port 2828
kf5.kio.core: Refilling KProtocolInfoFactory cache in the hope to find "ircs"
kf5.kio.core: Refilling KProtocolInfoFactory cache in the hope to find "mailto"
kf5.kio.core: Refilling KProtocolInfoFactory cache in the hope to find "irc"
Exception in thread "main" org.openqa.selenium.WebDriverException: connection refused
Build info: version: '3.7.1', revision: '8a0099a', time: '2017-11-06T21:01:39.354Z'
System info: host: 'linux-m2zi.suse', ip: 'Unknown', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.92-31-default', java.version: '1.8.0_144'
Driver info: driver.version: FirefoxDriver
remote stacktrace: stack backtrace:
   0:           0x4edb3c - backtrace::backtrace::trace::hc4bd56a2f176de7e
   1:           0x4edb72 - backtrace::capture::Backtrace::new::he3b2a15d39027c46
   2:           0x440ac8 - webdriver::error::WebDriverError::new::ha0fbd6d1a1131b43
   3:           0x447ba9 - geckodriver::marionette::MarionetteHandler::create_connection::hf0532ddb9e159684
   4:           0x428570 - <webdriver::server::Dispatcher<T, U>>::run::h2119c674d7b88193
   5:           0x4029b9 - std::sys_common::backtrace::__rust_begin_short_backtrace::h21d98a9ff86d4c25
   6:           0x40be65 - std::panicking::try::do_call::h5cff0c9b18cfdbba
   7:           0x5e6a6c - panic_unwind::__rust_maybe_catch_panic
                        at /checkout/src/libpanic_unwind/lib.rs:99
   8:           0x41eb22 - <F as alloc::boxed::FnBox<A>>::call_box::h413eb1d9d9f1c473
   9:           0x5df13b - alloc::boxed::{{impl}}::call_once<(),()>
                        at /checkout/src/liballoc/boxed.rs:692
                         - std::sys_common::thread::start_thread
                        at /checkout/src/libstd/sys_common/thread.rs:21
                         - std::sys::imp::thread::{{impl}}::new::thread_start
                        at /checkout/src/libstd/sys/unix/thread.rs:84
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$new$0(W3CHandshakeResponse.java:57)
    at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$getResponseFunction$2(W3CHandshakeResponse.java:104)
    at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
    at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
    at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:600)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:142)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:120)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:98)
    at com.seltri.webdriverdemo.main(webdriverdemo.java:14)

我已經嘗試了幾件事,但是對於這些東西我還是很陌生,所以我真的無法解決它。 我該怎么做才能解決此問題? 我也嘗試過使用RemoteWebDriver,但這也沒用。 我沒有用鉻等測試過。

我在Firefox 52.4中使用OpenSUSE Linux

您需要在此處進行一些更改:

  1. 而不是import org.openqa.selenium.*; 我們需要特定為import org.openqa.selenium.WebDriver;
  2. 您需要提供geckodriver的絕對路徑,如下所示:

     System.setProperty("webdriver.gecko.driver", "/usr/bin/geckodriver"); 

確保具有所需訪問權限的geckodriver二進制文件已復制到/usr/bin/目錄中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM