gpt4 book ai didi

java - Selenium FirefoxDriver 连接被拒绝

转载 作者:行者123 更新时间:2023-11-29 08:31:45 24 4
gpt4 key购买 nike

我有以下代码来测试 Selenium WebDriver。

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Starter
{
public static void main(String[] args)
{
WebDriver wd = new FirefoxDriver();
for(String arg: args) wd.get(arg);
wd.close();
}
}

它在我的工作站上运行,但不在服务器上运行。它给了我以下错误:

1511550749849   geckodriver     INFO    geckodriver 0.19.0
1511550749853 geckodriver INFO Listening on 127.0.0.1:65267
1511550750132 mozrunner::runner INFO Running command: "/usr/bin/firefox" "-marionette" "-profile" "/tmp/rust_mozprofile.svi5yF63xEow"

(firefox-esr:15207): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed

(firefox-esr:15207): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed

(firefox-esr:15207): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed

(firefox-esr:15207): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
1511550751081 Marionette INFO Listening on port 2828

(/usr/lib/firefox-esr/plugin-container:15330): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed

(/usr/lib/firefox-esr/plugin-container:15330): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed

(/usr/lib/firefox-esr/plugin-container:15330): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed

(/usr/lib/firefox-esr/plugin-container:15330): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
Exception in thread "main" org.openqa.selenium.WebDriverException: connection refused
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'ded5223', ip: '209.239.169.110', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.61reflected', java.version: '1.8.0_102'
Driver info: driver.version: FirefoxDriver
remote stacktrace: stack backtrace:
0: 0x4f388c - backtrace::backtrace::trace::h736111741fa0878e
1: 0x4f38c2 - backtrace::capture::Backtrace::new::h63b8a5c0787510c9
2: 0x442d88 - webdriver::error::WebDriverError::new::hea6d4dbf778b2b24
3: 0x449f99 - geckodriver::marionette::MarionetteHandler::create_connection::hf8b6061dba65cdd0
4: 0x42ac91 - <webdriver::server::Dispatcher<T, U>>::run::hba9181b5aacf8f04
5: 0x402c59 - std::sys_common::backtrace::__rust_begin_short_backtrace::h19de262639927233
6: 0x40c065 - std::panicking::try::do_call::h6c1659fc4d01af51
7: 0x5e38ec - panic_unwind::__rust_maybe_catch_panic
at /checkout/src/libpanic_unwind/lib.rs:98
8: 0x420d32 - <F as alloc::boxed::FnBox<A>>::call_box::h953e5f59694972c5
9: 0x5dc00b - alloc::boxed::{{impl}}::call_once<(),()>
at /checkout/src/liballoc/boxed.rs:661
- 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$22(ProtocolHandshake.java:365)
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:368)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:159)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:250)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:236)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:137)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:191)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:108)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:104)

另外,我在服务器上安装了 xvfb 并设置了 DISPLAY=:0,如果有的话。

请帮忙。

最佳答案

您使用的是什么版本的 Selenium 和 Firefox 浏览器?您正在使用 geckodriver 0.19.0,如 release notes 中所述,你应该使用:

  • Firefox 55.0(及更高版本)
  • Selenium 3.5(及更高版本)

无论如何,如果您使用的是推荐版本,您是否设置了 geckodriver 的路径?

你可以用不同的方式做到这一点:

  1. 在您的 PATH 环境变量中包含 GeckoDriver 位置,或者
  2. 通过 webdriver.gecko.driver 系统属性指定其位置(参见下面的示例),或者

        System.setProperty("webdriver.gecko.driver", "yourPathTo/geckodriver");
    WebDriver driver = new FirefoxDriver();
    driver.get("https://www.google.co.uk/");
  3. 将你的 geckodriver 移动到 /usr/local/bin/

最后,无论如何,请确保您的 geckodriver 是可执行的:

chmod +x geckodriver

关于java - Selenium FirefoxDriver 连接被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47479155/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com