How to Import Org.Openqa.Selenium.Webdriver Using Selenium and Java 11

Unable to import org.openqa.selenium.WebDriver using Selenium and Java 11

As per Can't compile Java9 module with selenium-java as dependency it seems the Selenium packages can't be compiled with Java 9 due to split packages and till May 15, 2018 Selenium wasn't fully compatible with Java 9.

But as per this comment @Jarob22 mentioned, Selenium works just fine using Java 10. Java 9 is already eol and there's not much point adding extra stuff to try and support just it if 10 works.

But with the landing of e57914a Simon introduced us with basic JPMS support. With this availability (mhomnag/selenium-java10-reproducer@bc63889) now actually builds but you may have to Remove the WebDriverWaiter and just use a sleep for now.


Java 11

As you are using java.version: '11.0.1', selenium-server-standalone-3.141.59.jar is still not compatible with Java 11. But once Java 11 ships and Buck supports it the toolchain witll be rejiged to support Java 11.


Solution

The strategic solution will be to install the latest version of JDK 8u212 and execute the @Tests

Selenium - Not able to import package 'org.openqa.selenium.environment'

But i can be able to find this in the selenium source code.
https://github.com/SeleniumHQ/selenium/tree/master/java/client/test/org/openqa/selenium/environment

Notice that that URL contains /test/ . In other words, that class belongs to the unit tests rather than the production code, which is why you can't find it in the production jars.

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

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 (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 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:

  • Upgrade JDK to recent levels JDK 8u251.

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:

  • “Component not initialized” nsresult: “0xc1f30001 (NS_ERROR_NOT_INITIALIZED)” error with Selenium GeckoDriver and Mozilla
  • WebDriverException: Message: Exception… “Failure” nsresult: “0x80004005 (NS_ERROR_FAILURE)” while saving a large html file using Selenium Python


Outro

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



Related Topics



Leave a reply



Submit