简体   繁体   中英

org.openqa.selenium.WebDriverException: [Exception… “Component not initialized” error using GeckoDriver and Tor browser with Selenium Java

I tried to run Selenium with Tor Browser but get an error. When i start my code, the Tor Browser opens and calls the url https://www.trash-mail.com/adresse-erstellen/ correctly but instead of making the last command with "sendKeys" this error occurres:

Exception in thread "main" org.openqa.selenium.WebDriverException: [Exception... "Component not initialized"  nsresult: "0xc1f30001 (NS_ERROR_NOT_INITIALIZED)"  location: "JS frame :: chrome://marionette/content/modal.js :: get window :: line 143"  data: no]
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'MacBook-Pro.local', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6', java.version: '14.0.1'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 68.9.0, javascriptEnabled: true, moz:accessibilityChecks: false, moz:buildID: 20200407010101, moz:geckodriverVersion: 0.25.0, moz:headless: false, moz:processID: 21229, moz:profile: /var/folders/5s/9gmx38s53zl..., moz:shutdownTimeout: 60000, moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: MAC, platformName: MAC, platformVersion: 18.7.0, rotatable: false, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: d12a4cf5-9c6f-1549-9dc4-c272dcc7aaee
*** Element info: {Using=css selector, value=#form-password-new1}
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:323)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByCssSelector(RemoteWebDriver.java:420)
    at org.openqa.selenium.By$ByCssSelector.findElement(By.java:431)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:315)
    at com.eviltester.webdriver.Connection.open(Connection:28)

Here is my code so far:

package com.eviltester.webdriver;

import java.io.File;
import java.io.IOException;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;

public class Connection {

    private static final String macPath = "/Users/Admin/Documents/Projekte/workspace/project1/webdriver/geckodriver";
    private static final String torPath = "/Users/Admin/Documents/Projekte/workspace/project1/webdriver/tor";
    private static final String torFirefox = "/Applications/Tor Browser.app/Contents/MacOS/firefox";
    private static final String torProfile ="/Applications/Tor Browser.app/Contents/Resources/TorBrowser/Tor";
    
    private FirefoxOptions options = new FirefoxOptions();
    
    public Connection() {
        System.setProperty("webdriver.gecko.driver", macPath);
    }
    
    public void open() {
        FirefoxProfile profile = new FirefoxProfile(new File(torProfile));
        FirefoxBinary binary = new FirefoxBinary(new File(torFirefox));
        
        options.setBinary(binary);
        options.setProfile(profile);
        FirefoxDriver driver = new FirefoxDriver(options);
        
        driver.navigate().to("https://www.trash-mail.com/adresse-erstellen/");
        TimeUnit.SECONDS.sleep(5);
        WebDriverWait wait = new WebDriverWait(driver, 10);
        wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("#form-postbox-new"))).sendKeys("testmail123");

    }
}

Would be nice if someone could help me with my problem.

Which Geckodriver version do you use? I am asking because there is an issue with the firefox driver version < 69: https://bugzilla.mozilla.org/show_bug.cgi?id=1477977 , https://github.com/mozilla/geckodriver/issues/1690 . I had the same error but it occurred when I tried to interact with modal windows, not when calling sendKeys.

If possible, try to update the version of the driver and see if the problem persists.

This error message...

Exception in thread "main" org.openqa.selenium.WebDriverException: [Exception... "Component not initialized"  nsresult: "0xc1f30001 (NS_ERROR_NOT_INITIALIZED)"  location: "JS frame :: chrome://marionette/content/modal.js :: get window :: line 143"  data: no]

...implies that that the Marionette threw an error while attempting to interacting with the desired element.


It seems the get window was invoked too early even before the DOM Tree was completely rendered. To be more specific addEventListener was invoked even before the Browser Client (ie the Web Browser) have attained 'document.readyState' equal to "complete" . Generally once this condition is fulfilled Selenium performs the next line of code.


Solution

A quick solution will be to before you try to interact with any of the element on a fresh loaded webpage instead of ExpectedConditions as presenceOfElementLocated you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies :

  • Using id :

     new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.id("form-postbox-new"))).sendKeys("testmail123");
  • Using cssSelector :

     new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("#form-postbox-new"))).sendKeys("testmail123");
  • Using xpath :

     new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='form-postbox-new']"))).sendKeys("testmail123");

Additional Considerations

Ensure that:

Note : Selenium have issues with Java 9 , Java 11 and Java 13 .

  • Upgrade Selenium to current levels Version 3.141.59 .
  • Upgrade GeckoDriver to GeckoDriver v0.26.0 level.
  • Firefox is upgraded to current _Firefox v77.0.1 _ levels.
  • Ensure that the version of the binaries you are using are compatable.

You can find a detailed discussion in Which Firefox browser versions supported for given Geckodriver version?

  • GeckoDriver is present in the desired location.
  • GeckoDriver is having executable permission for non-root users.
  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client .
  • Take a System Reboot .
  • Execute your Test as a non-root user.
  • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.

References

You can find a couple of relevant discussions in:


Outro

Occur the 'NS_ERROR_NOT_INITIALIZED' when switching the window to bottom dock.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: unexpected command response using Selenium Java org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0 using GeckoDriver Firefox and Selenium error“ org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/” with GeckoDriver and Firefox org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:1941 with GeckoDriver and Selenium org.openqa.selenium.WebDriverException: disconnected: not connected to DevTools error using ChromeDriver Chrome using Selenium and Java org.openqa.selenium.WebDriverException: unknown error: cannot focus element using ChromeDriver Selenium and Java org.openqa.selenium.WebDriverException: unknown error: chrome failed to start using Selenium ChromeDriver and Chrome through Java org.openqa.selenium.WebDriverException: chrome not reachable using Selenium and ChromeDriver Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: cannot determine loading status error while clicking using Selenium org.openqa.selenium.WebDriverException: Browser failed to start, test in fluentlium
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM