簡體   English   中英

org.openqa.selenium.TimeoutException:在使用 AutoCloseable 在 Ubuntu 中運行無頭 firefox 瀏覽器時連接被拒絕錯誤

[英]org.openqa.selenium.TimeoutException: connection refused error while running headless firefox browser in Ubuntu using AutoCloseable

錯誤:

org.openqa.selenium.TimeoutException:連接被拒絕構建信息:版本:'3.141.59',修訂版:'e82be7d358',時間:'2018-11-14T08:25:48' 系統信息:主機:'ubuntu',Z94535B52768FCAD39D28 : '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.15.0-112-generic', java.version: '1.8.0_252' 驅動程序信息:驅動程序.version: FirefoxDriver

代碼:

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);
// code does not reach this point. Look like its freezing at the initialisation of 'driver'.
try (AutoCloseable autoCloseable = () -> driver.close()) {
         ...

我已將 Java 版本更改為另一個建議的問題(從 11 到 8)。

編輯:那個帖子( Java Selenium Webdriver Connection Refused )沒有工作。

編輯#2:我通過 Tomcat 9 運行它。

我沒有看到您的代碼塊有任何此類問題。 我采用了您的代碼並使用以下配置執行:


執行細節

以下是使用的執行細節:

  • 代碼塊:

     import java.util.logging.Level; import org.openqa.selenium.firefox.FirefoxDriver; //import org.openqa.selenium.firefox.FirefoxDriverLogLevel; import org.openqa.selenium.firefox.FirefoxOptions; public class AutoCloseableSelenium { public static void main(String[] args) throws Exception { System.setProperty("webdriver.gecko.driver","C:\\WebDrivers\\geckodriver.exe"); FirefoxOptions options = new FirefoxOptions(); options.setHeadless(true); //options.setLogLevel(FirefoxDriverLogLevel.TRACE); java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.OFF); System.out.println(1); FirefoxDriver driver = new FirefoxDriver(options); try (AutoCloseable autoCloseable = () -> driver.quit()) { } System.out.println("Exiting program"); }

    }

  • 控制台 Output:

     1 1595977246813 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "-marionette" "-headless" "-foreground" "-no-remote" "-profile" "C:\\Users\\SOMABH~1\\AppData\\Local\\Temp\\rust_mozprofile345iC4" *** You are running in headless mode. JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory. console.error: SearchCache: "_readCacheFile: Error reading cache file:" (new Error("", "(unknown module)")) 1595977254325 Marionette INFO Listening on port 53331 1595977254676 Marionette WARN TLS certificate errors will be ignored for this session 1595977254896 Marionette INFO Stopped listening on port 53331 JavaScript error: resource://activity-stream/lib/ActivityStreamPrefs.jsm, line 27: NS_ERROR_ILLEGAL_VALUE: Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIPrefBranch.removeObserver] console.warn: services.settings: main/messaging-experiments sync interrupted by shutdown JavaScript error: resource://services-settings/IDBHelpers.jsm, line 24: Error: IndexedDB: main/fxmonitor-breaches list() IndexedDB: execute() The application is shutting down JavaScript error: resource://gre/modules/Sqlite.jsm, line 928: Error: Connection is not open. Exiting program

暫無
暫無

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

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