org.openqa.selenium.TimeoutException: ошибка подключения отклонена при запуске браузера Firefox без браузера в Ubuntu с использованием AutoCloseable

Ошибка:

org.openqa.selenium.TimeoutException: в соединении отказано Информация о сборке: версия: '3.141.59', ревизия: 'e82be7d358', время: '2018-11-14T08: 25: 48' Информация о системе: хост: 'ubuntu', ip : '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.


person user12346306    schedule 28.07.2020    source источник


Ответы (1)


Я не вижу такой проблемы с вашим блоком кода. Я взял ваш код и выполнил его со следующей конфигурацией:


Детали исполнения

Вот подробности выполнения с использованием autocloseable:

  • Блок кода:

    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");
      }
    

    }

  • Консольный вывод:

    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
    
person DebanjanB    schedule 28.07.2020
comment
если это что-то значит, я запускаю это через веб-приложение tomcat. - person user12346306; 29.07.2020
comment
@ user12346306 Вы не рассказали нам о своих двоичных конфигурациях. - person DebanjanB; 29.07.2020
comment
Я не понимаю, что такое «бинарные конфигурации», не могли бы вы уточнить? - person user12346306; 29.07.2020