英文:
Selenium stuck on WebDriver object
问题
org.openqa.selenium.TimeoutException: 连接被拒绝
构建信息:版本:'3.141.59',修订版本:'e82be7d358',时间:'2018-11-14T08:25:48'
系统信息:主机:'ubuntu',IP:'127.0.0.1',操作系统名称:'Linux',操作系统架构:'amd64',操作系统版本:'4.15.0-112-generic',Java 版本:'11.0.8'
驱动程序信息:驱动程序版本:FirefoxDriver
我正在尝试使用 Selenium 连接到一个网站,在我的个人电脑上进行测试时可以正常工作,但在服务器上运行时会抛出此错误...
代码:
System.out.println(1);
System.setProperty("webdriver.gecko.driver", "/usr/bin/geckodriver");
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setHeadless(true);
java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.OFF);
System.out.println(1);
WebDriver driver = new FirefoxDriver(firefoxOptions);
System.out.println("starting...");
try (AutoCloseable autoCloseable = () -> driver.close()) {
driver.get("https://website.com");
System.out.println(1);
....
输出:
1
1
1595767726383 mozrunner::runner INFO 正在运行命令:" /usr/lib/firefox/firefox" "-marionette" "-headless" "-foreground" "-no-remote" "-profile" "/tmp/rust$"
*** 您正在以无头模式运行。
由于某种原因,代码没有执行到 try-with-resource 块,有人可以帮助解决这个问题吗?
(根据我目前所知,它似乎卡在了 WebDriver 初始化上)
编辑:我阅读了 https://stackoverflow.com/questions/63102699/selenium-stuck-on-webdriver-object 帖子,但它并没有提供任何帮助,因为我的 Java 版本已经是 1.8。
<details>
<summary>英文:</summary>
org.openqa.selenium.TimeoutException: connection refused
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'ubuntu', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.15.0-112-generic', java.version: '11.0.8'
Driver info: driver.version: FirefoxDriver
I am trying to connect to a website using selenium, when I test this on my PC it works fine, but when I run it on a server it throws this error...
Code:
```java
System.out.println(1);
System.setProperty("webdriver.gecko.driver", "/usr/bin/geckodriver");
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setHeadless(true);
java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.OFF);
System.out.println(1);
WebDriver driver = new FirefoxDriver(firefoxOptions);
System.out.println("starting...");
try (AutoCloseable autoCloseable = () -> driver.close()) {
driver.get("https://website.com");
System.out.println(1);
....
Output:
1
1
1595767726383 mozrunner::runner INFO Running command: "/usr/lib/firefox/firefox" "-marionette" "-headless" "-foreground" "-no-remote" "-profile" "/tmp/rust$
*** You are running in headless mode.
for some reason this is not making it to the try-with-resource block, can someone shine some light on this?
(From what I know so far its stuck on the WebDriver initialisation)
EDIT: I read the thread https://stackoverflow.com/questions/63102699/selenium-stuck-on-webdriver-object and it did not provide any assistance as my Java version is already using 1.8.
专注分享java语言的经验与见解,让所有开发者获益!
评论