2

I am trying to execute my code in Firefox, sometimes it works but majority of time i get exception as:

[Exception... "Component not initialized"  nsresult: "0xc1f30001 (NS_ERROR_NOT_INITIALIZED)"  location: "JS frame :: chrome://marionette/content/dom.js :: addEventListener :: line 67"  data: no]

Its happening from last week, previously it was working fine for me.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Shakir
  • 123
  • 1
  • 4
  • 14

3 Answers3

3

NS_ERROR_NOT_INITIALIZED resembles an attempt which was made to use a component or object which has not yet been initialized. These components usually provide an initialization method, often called Init which must be called before any other methods which are being used.

However, this error message...

[Exception... "Component not initialized"  nsresult: "0xc1f30001 (NS_ERROR_NOT_INITIALIZED)"  location: "JS frame :: chrome://marionette/content/dom.js :: addEventListener :: line 67"  data: no]

...implies that the Marionette threw an error while invoking addEventListener as defined in dom.js

Your code trials and the relevant HTML DOM would have helped us to debug the issue in a better way. However it seems the addEventListener was invoked too early even before the DOM Tree was completely rendered. To be more specific addEventListener was invoked even before the Browser Client (i.e. 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 you need to induce WebDriverWait for either of the following expected_conditions:

An example

  • Python:

    • Code Block:

      driver.get("https://stackoverflow.com");
      WebDriverWait(driver, 10).until(EC.title_contains("Stack"))
      print("Page Title is : "+driver.title)
      
    • Console Output:

      Page Title is : Stack Overflow - Where Developers Learn, Share, & Build Careers 
      
  • Java:

    • Code Block:

      driver.get("https://stackoverflow.com");
      new WebDriverWait(driver, 10).until(ExpectedConditions.titleContains("Stack"));
      System.out.println("Page Title is : "+driver.getTitle());
      
    • Console Output:

      Page Title is : Stack Overflow - Where Developers Learn, Share, & Build Careers 
      

Additional Considerations

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.
  • Upgrade Firefox version to Firefox v69.0 levels.
  • 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.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

It seems you're suffering from Geckodriver Issue 1263, you can try the following workarounds:

  1. Update Selenium client library to the latest stable which is 3.141.59 as of now, it's better to use package management system like Maven or Gradle as update of dependencies libraries might be required. If you're not using Java check out Web - Desktop and Mobile Browsers article for code examples for different Selenium client languages like JavaScript, Python, C#, etc.

  2. Make sure to use the latest version of Firefox

  3. Make sure to use the latest version of Geckodriver

If you will be still experiencing problems you can consider raising a new issue in the Geckodriver project, be prepared to provide as much information as possible (the same applies to next questions here if any)

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
0

On my case, some configs were wrong. I was trying to block pop-up downloads, but something went wrong.Here is the code that I had to remove, and it worked (on this specific case):

FirefoxProfile profile = new FirefoxProfile();

profile.setPreference("browser.download.dir", "C:\\Temp");
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv");
profile.setPreference("pdfjs.disabled", true);
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.panel.shown", false);

DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
capabilities.setCapability(CapabilityType.ELEMENT_SCROLL_BEHAVIOR, 1);

driver = new FirefoxDriver(capabilities);