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.
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.
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");
Ensure that:
Note: Selenium have issues with Java 9, Java 11 and Java 13.
You can find a detailed discussion in Which Firefox browser versions supported for given Geckodriver version?
Test
as a non-root user.driver.quit()
within tearDown(){}
method to close & destroy the WebDriver and Web Client instances gracefully.You can find a couple of relevant discussions in:
Occur the 'NS_ERROR_NOT_INITIALIZED' when switching the window to bottom dock.