This is my code:
WebDriverManager.chromedriver().setup();
System.setProperty("webdriver.chrome.driver", "src/main/extras/chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
WebDriver driver = new ChromeDriver(options);
driver = new ChromeDriver();
driver.get(url);
The last line, getting the URL, is giving this error:
Exception in thread "Thread-3" java.lang.NullPointerException
I wasn't getting this error before I tried to launch the browser in headless mode.
This is my full error message thing:
"D:\Program Files\Amazon Corretto\jdk11.0.11_9\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2021.2\lib\idea_rt.jar=59273:C:\Program Files\JetBrains\IntelliJ IDEA 2021.2\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\jackg\.m2\repository\org\openjfx\javafx-controls\11.0.2\javafx-controls-11.0.2.jar;C:\Users\jackg\.m2\repository\org\openjfx\javafx-graphics\11.0.2\javafx-graphics-11.0.2.jar;C:\Users\jackg\.m2\repository\org\openjfx\javafx-fxml\11.0.2\javafx-fxml-11.0.2.jar;C:\Users\jackg\.m2\repository\org\openjfx\javafx-web\11.0.2\javafx-web-11.0.2.jar;C:\Users\jackg\.m2\repository\org\openjfx\javafx-media\11.0.2\javafx-media-11.0.2.jar;C:\Users\jackg\.m2\repository\org\openjfx\javafx-base\11.0.1\javafx-base-11.0.1.jar;C:\Users\jackg\.m2\repository\org\seleniumhq\selenium\selenium-java\4.1.1\selenium-java-4.1.1.jar;C:\Users\jackg\.m2\repository\com\google\auto\service\auto-service-annotations\1.0.1\auto-service-annotations-1.0.1.jar;C:\Users\jackg\.m2\repository\com\google\auto\service\auto-service\1.0.1\auto-service-1.0.1.jar;C:\Users\jackg\.m2\repository\com\google\auto\auto-common\1.2\auto-common-1.2.jar;C:\Users\jackg\.m2\repository\org\seleniumhq\selenium\selenium-devtools-v85\4.1.1\selenium-devtools-v85-4.1.1.jar;C:\Users\jackg\.m2\repository\org\seleniumhq\selenium\selenium-devtools-v94\4.1.1\selenium-devtools-v94-4.1.1.jar;C:\Users\jackg\.m2\repository\org\seleniumhq\selenium\selenium-devtools-v95\4.1.1\selenium-devtools-v95-4.1.1.jar;C:\Users\jackg\.m2\repository\org\seleniumhq\selenium\selenium-devtools-v96\4.1.1\selenium-devtools-v96-4.1.1.jar;C:\Users\jackg\.m2\repository\org\seleniumhq\selenium\selenium-edge-driver\4.1.1\selenium-edge-driver-4.1.1.jar;C:\Users\jackg\.m2\repository\org\seleniumhq\selenium\selenium-firefox-driver\4.1.1\selenium-firefox-driver-4.1.1.jar;C:\Users\jackg\.m2\repository\org\seleniumhq\selenium\selenium-firefox-xpi-driver\4.1.1\selenium-firefox-xpi-driver-4.1.1.jar;C:\Users\jackg\.m2\repository\org\seleniumhq\selenium\selenium-ie-driver\4.1.1\selenium-ie-driver-4.1.1.jar;C:\Users\jackg\.m2\repository\org\seleniumhq\selenium\selenium-opera-driver\4.1.1\selenium-opera-driver-4.1.1.jar;C:\Users\jackg\.m2\repository\io\netty\netty-codec\4.1.70.Final\netty-codec-4.1.70.Final.jar;C:\Users\jackg\.m2\repository\io\netty\netty-handler\4.1.70.Final\netty-handler-4.1.70.Final.jar;C:\Users\jackg\.m2\repository\io\netty\netty-resolver\4.1.70.Final\netty-resolver-4.1.70.Final.jar;C:\Users\jackg\.m2\repository\io\opentelemetry\opentelemetry-exporter-logging\1.9.1\opentelemetry-exporter-logging-1.9.1.jar;C:\Users\jackg\.m2\repository\io\opentelemetry\opentelemetry-sdk-metrics\1.9.1-alpha\opentelemetry-sdk-metrics-1.9.1-alpha.jar;C:\Users\jackg\.m2\repository\io\opentelemetry\opentelemetry-sdk-logs\1.9.1-alpha\opentelemetry-sdk-logs-1.9.1-alpha.jar;C:\Users\jackg\.m2\repository\io\opentelemetry\opentelemetry-api-metrics\1.9.1-alpha\opentelemetry-api-metrics-1.9.1-alpha.jar;C:\Users\jackg\.m2\repository\org\asynchttpclient\async-http-client-netty-utils\2.12.3\async-http-client-netty-utils-2.12.3.jar;C:\Users\jackg\.m2\repository\io\netty\netty-codec-socks\4.1.60.Final\netty-codec-socks-4.1.60.Final.jar;C:\Users\jackg\.m2\repository\io\netty\netty-handler-proxy\4.1.60.Final\netty-handler-proxy-4.1.60.Final.jar;C:\Users\jackg\.m2\repository\io\netty\netty-transport-native-epoll\4.1.60.Final\netty-transport-native-epoll-4.1.60.Final-linux-x86_64.jar;C:\Users\jackg\.m2\repository\io\netty\netty-transport-native-kqueue\4.1.60.Final\netty-transport-native-kqueue-4.1.60.Final-osx-x86_64.jar;C:\Users\jackg\.m2\repository\org\reactivestreams\reactive-streams\1.0.3\reactive-streams-1.0.3.jar;C:\Users\jackg\.m2\repository\com\typesafe\netty\netty-reactive-streams\2.0.4\netty-reactive-streams-2.0.4.jar;C:\Users\jackg\.m2\repository\com\sun\activation\jakarta.activation\1.2.2\jakarta.activation-1.2.2.jar;C:\Users\jackg\.m2\repository\org\seleniumhq\selenium\selenium-safari-driver\4.1.1\selenium-safari-driver-4.1.1.jar;C:\Users\jackg\.m2\repository\org\slf4j\slf4j-api\1.7.32\slf4j-api-1.7.32.jar;C:\Users\jackg\.m2\repository\com\google\code\gson\gson\2.8.8\gson-2.8.8.jar;C:\Users\jackg\.m2\repository\org\jsoup\jsoup\1.14.2\jsoup-1.14.2.jar;C:\Users\jackg\.m2\repository\com\github\docker-java\docker-java\3.2.12\docker-java-3.2.12.jar;C:\Users\jackg\.m2\repository\com\github\docker-java\docker-java-core\3.2.12\docker-java-core-3.2.12.jar;C:\Users\jackg\.m2\repository\com\github\docker-java\docker-java-api\3.2.12\docker-java-api-3.2.12.jar;C:\Users\jackg\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.10.3\jackson-annotations-2.10.3.jar;C:\Users\jackg\.m2\repository\commons-io\commons-io\2.6\commons-io-2.6.jar;C:\Users\jackg\.m2\repository\org\apache\commons\commons-compress\1.21\commons-compress-1.21.jar;C:\Users\jackg\.m2\repository\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;C:\Users\jackg\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.10.3\jackson-databind-2.10.3.jar;C:\Users\jackg\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.10.3\jackson-core-2.10.3.jar;C:\Users\jackg\.m2\repository\org\bouncycastle\bcpkix-jdk15on\1.64\bcpkix-jdk15on-1.64.jar;C:\Users\jackg\.m2\repository\org\bouncycastle\bcprov-jdk15on\1.64\bcprov-jdk15on-1.64.jar;C:\Users\jackg\.m2\repository\org\slf4j\jcl-over-slf4j\1.7.30\jcl-over-slf4j-1.7.30.jar;C:\Users\jackg\.m2\repository\com\github\docker-java\docker-java-transport-httpclient5\3.2.12\docker-java-transport-httpclient5-3.2.12.jar;C:\Users\jackg\.m2\repository\com\github\docker-java\docker-java-transport\3.2.12\docker-java-transport-3.2.12.jar;C:\Users\jackg\.m2\repository\org\apache\httpcomponents\client5\httpclient5\5.0.3\httpclient5-5.0.3.jar;C:\Users\jackg\.m2\repository\org\apache\httpcomponents\core5\httpcore5\5.0.2\httpcore5-5.0.2.jar;C:\Users\jackg\.m2\repository\commons-codec\commons-codec\1.13\commons-codec-1.13.jar;C:\Users\jackg\.m2\repository\com\google\guava\failureaccess\1.0.1\failureaccess-1.0.1.jar;C:\Users\jackg\.m2\repository\com\google\guava\listenablefuture\9999.0-empty-to-avoid-conflict-with-guava\listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar;C:\Users\jackg\.m2\repository\com\google\code\findbugs\jsr305\3.0.2\jsr305-3.0.2.jar;C:\Users\jackg\.m2\repository\org\checkerframework\checker-qual\3.8.0\checker-qual-3.8.0.jar;C:\Users\jackg\.m2\repository\com\google\errorprone\error_prone_annotations\2.5.1\error_prone_annotations-2.5.1.jar;C:\Users\jackg\.m2\repository\com\google\j2objc\j2objc-annotations\1.3\j2objc-annotations-1.3.jar;C:\Users\jackg\.m2\repository\org\brotli\dec\0.1.2\dec-0.1.2.jar;C:\Users\jackg\.m2\repository\org\apache\commons\commons-lang3\3.12.0\commons-lang3-3.12.0.jar;C:\Users\jackg\.m2\repository\org\apache\commons\commons-text\1.9\commons-text-1.9.jar;C:\Users\jackg\.m2\repository\commons-beanutils\commons-beanutils\1.9.4\commons-beanutils-1.9.4.jar;C:\Users\jackg\.m2\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;C:\Users\jackg\.m2\repository\commons-collections\commons-collections\3.2.2\commons-collections-3.2.2.jar;C:\Users\jackg\.m2\repository\org\apache\commons\commons-collections4\4.4\commons-collections4-4.4.jar -p "C:\Users\jackg\.m2\repository\org\openjfx\javafx-base\11.0.1\javafx-base-11.0.1-win.jar;C:\Users\jackg\.m2\repository\io\netty\netty-transport-classes-kqueue\4.1.70.Final\netty-transport-classes-kqueue-4.1.70.Final.jar;C:\Users\jackg\.m2\repository\org\controlsfx\controlsfx\11.1.0\controlsfx-11.1.0.jar;C:\Users\jackg\.m2\repository\net\synedra\validatorfx\0.1.13\validatorfx-0.1.13.jar;C:\Users\jackg\.m2\repository\io\opentelemetry\opentelemetry-sdk\1.9.1\opentelemetry-sdk-1.9.1.jar;C:\Users\jackg\.m2\repository\org\openjfx\javafx-graphics\11.0.2\javafx-graphics-11.0.2-win.jar;C:\Users\jackg\.m2\repository\org\openjfx\javafx-fxml\11.0.2\javafx-fxml-11.0.2-win.jar;C:\Users\jackg\.m2\repository\com\beust\jcommander\1.81\jcommander-1.81.jar;C:\Users\jackg\.m2\repository\org\openjfx\javafx-controls\11.0.2\javafx-controls-11.0.2-win.jar;C:\Users\jackg\.m2\repository\org\seleniumhq\selenium\selenium-chromium-driver\4.1.1\selenium-chromium-driver-4.1.1.jar;C:\Users\jackg\.m2\repository\io\netty\netty-transport-classes-epoll\4.1.70.Final\netty-transport-classes-epoll-4.1.70.Final.jar;C:\Users\jackg\.m2\repository\org\seleniumhq\selenium\selenium-api\4.1.1\selenium-api-4.1.1.jar;C:\Users\jackg\.m2\repository\org\seleniumhq\selenium\selenium-json\4.1.1\selenium-json-4.1.1.jar;C:\Users\jackg\.m2\repository\net\java\dev\jna\jna\5.8.0\jna-5.8.0.jar;C:\Users\jackg\.m2\repository\io\opentelemetry\opentelemetry-sdk-extension-autoconfigure-spi\1.9.1\opentelemetry-sdk-extension-autoconfigure-spi-1.9.1.jar;C:\Users\jackg\.m2\repository\net\jodah\failsafe\2.4.4\failsafe-2.4.4.jar;C:\Users\jackg\.m2\repository\io\netty\netty-transport-native-unix-common\4.1.70.Final\netty-transport-native-unix-common-4.1.70.Final.jar;C:\Users\jackg\.m2\repository\io\netty\netty-codec-http\4.1.70.Final\netty-codec-http-4.1.70.Final.jar;C:\Users\jackg\.m2\repository\io\opentelemetry\opentelemetry-sdk-extension-autoconfigure\1.9.1-alpha\opentelemetry-sdk-extension-autoconfigure-1.9.1-alpha.jar;C:\Users\jackg\.m2\repository\net\bytebuddy\byte-buddy\1.12.2\byte-buddy-1.12.2.jar;C:\Users\jackg\.m2\repository\io\netty\netty-buffer\4.1.70.Final\netty-buffer-4.1.70.Final.jar;C:\Users\jackg\.m2\repository\io\github\bonigarcia\webdrivermanager\5.0.3\webdrivermanager-5.0.3.jar;C:\Users\jackg\.m2\repository\io\opentelemetry\opentelemetry-sdk-common\1.9.1\opentelemetry-sdk-common-1.9.1.jar;C:\Users\jackg\.m2\repository\org\apache\commons\commons-exec\1.3\commons-exec-1.3.jar;C:\Users\jackg\.m2\repository\io\netty\netty-common\4.1.70.Final\netty-common-4.1.70.Final.jar;C:\Users\jackg\.m2\repository\org\kordamp\ikonli\ikonli-javafx\12.2.0\ikonli-javafx-12.2.0.jar;C:\Users\jackg\.m2\repository\com\dlsc\formsfx\formsfx-core\11.4.2\formsfx-core-11.4.2.jar;C:\Users\jackg\.m2\repository\io\opentelemetry\opentelemetry-sdk-trace\1.9.1\opentelemetry-sdk-trace-1.9.1.jar;C:\Users\jackg\.m2\repository\io\opentelemetry\opentelemetry-api\1.9.1\opentelemetry-api-1.9.1.jar;C:\Users\jackg\.m2\repository\org\openjfx\javafx-web\11.0.2\javafx-web-11.0.2-win.jar;C:\Users\jackg\.m2\repository\io\opentelemetry\opentelemetry-context\1.9.1\opentelemetry-context-1.9.1.jar;C:\Users\jackg\.m2\repository\com\google\guava\guava\30.1.1-jre\guava-30.1.1-jre.jar;C:\Users\jackg\.m2\repository\org\seleniumhq\selenium\selenium-chrome-driver\4.1.1\selenium-chrome-driver-4.1.1.jar;C:\Users\jackg\.m2\repository\com\opencsv\opencsv\5.5.2\opencsv-5.5.2.jar;C:\Users\jackg\.m2\repository\org\seleniumhq\selenium\selenium-support\4.1.1\selenium-support-4.1.1.jar;C:\Users\jackg\.m2\repository\org\kordamp\bootstrapfx\bootstrapfx-core\0.4.0\bootstrapfx-core-0.4.0.jar;C:\Users\jackg\.m2\repository\org\openjfx\javafx-media\11.0.2\javafx-media-11.0.2-win.jar;C:\Users\jackg\.m2\repository\eu\hansolo\tilesfx\11.48\tilesfx-11.48.jar;C:\Users\jackg\.m2\repository\org\seleniumhq\selenium\selenium-http\4.1.1\selenium-http-4.1.1.jar;C:\Users\jackg\.m2\repository\org\asynchttpclient\async-http-client\2.12.3\async-http-client-2.12.3.jar;C:\Users\jackg\.m2\repository\io\opentelemetry\opentelemetry-semconv\1.9.1-alpha\opentelemetry-semconv-1.9.1-alpha.jar;C:\Users\jackg\.m2\repository\io\ous\jtoml\2.0.0\jtoml-2.0.0.jar;C:\Users\jackg\.m2\repository\org\seleniumhq\selenium\selenium-remote-driver\4.1.1\selenium-remote-driver-4.1.1.jar;C:\Users\jackg\.m2\repository\io\netty\netty-transport\4.1.70.Final\netty-transport-4.1.70.Final.jar;C:\Users\jackg\.m2\repository\org\kordamp\ikonli\ikonli-core\12.2.0\ikonli-core-12.2.0.jar;D:\Users\jackg\Desktop\Java Code\Ethermine Tracker JavaFX\target\classes" -m com.traptricker.etherminetrackerjavafx/com.traptricker.etherminetrackerjavafx.Main
Dec 30, 2021 9:22:25 PM javafx.fxml.FXMLLoader$ValueElement processValue
WARNING: Loading FXML document with JavaFX API of version 17 by JavaFX runtime of version 11.0.1
Starting program...
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Starting ChromeDriver 95.0.4638.17 (a9d0719444d4b035e284ed1fce73bf6ccd789df2-refs/branch-heads/4638#{#178}) on port 63013
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
[1640917354.440][WARNING]: This version of ChromeDriver has not been tested with Chrome version 96.
Dec 30, 2021 9:22:34 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Dec 30, 2021 9:22:34 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
INFO: Found exact CDP implementation for version 96
Starting ChromeDriver 95.0.4638.17 (a9d0719444d4b035e284ed1fce73bf6ccd789df2-refs/branch-heads/4638#{#178}) on port 53163
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
[1640917356.435][WARNING]: This version of ChromeDriver has not been tested with Chrome version 96.
Dec 30, 2021 9:22:36 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Dec 30, 2021 9:22:36 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
INFO: Found exact CDP implementation for version 96
Exception in thread "Thread-3" java.lang.NullPointerException
at com.traptricker.etherminetrackerjavafx/com.traptricker.etherminetrackerjavafx.SeleniumScrapper.setUpWebdriver(SeleniumScrapper.java:31)
at com.traptricker.etherminetrackerjavafx/com.traptricker.etherminetrackerjavafx.Controller.trackEthermine(Controller.java:54)
at java.base/java.lang.Thread.run(Thread.java:829)
You need to take care of a few things here:
You have already download the ChromeDriver and accessing it as:
System.setProperty("webdriver.chrome.driver", "src/main/extras/chromedriver.exe");
Additionally you are also downloading ChromeDriver through WebDriverManager as:
WebDriverManager.chromedriver().setup();
As a result your program have access to multiple instances of ChromeDriver. Hence you see:
Exception in thread "Thread-3" java.lang.NullPointerException
Solution
You need to use only one instance of ChromeDriver either the downloaded version or the one downloaded and accessed through WebDriverManager
Related
I'm running simple Selenium test, which uses selenium version 4.0.0 and chromedriver version 109. I'm running automation test on Salesforce application, which logs into the application and performs some operation. In the middle of the test execution, I get below error:
Jan 23, 2023 7:58:23 PM org.openqa.selenium.devtools.Connection handle
INFO: <- {"method":"Inspector.detached","params":{"reason":"target_closed"}}
Jan 23, 2023 7:58:23 PM org.openqa.selenium.devtools.Connection handle
INFO: Method Inspector.detached called with 0 callbacks available
After this connection to the browser is lost and when any further selenium webdriver statement(e.g. findElement) is executed, I gives exception:
org.openqa.selenium.NoSuchWindowException: no such window: target window already closed
from unknown error: web view not found
Can someone please help me with this ?
I tried different ways to fix the problem, Removed 'Thread.sleep' and updated browser capabilities as mentioned in this post, but it didn't work:
org.openqa.selenium.WebDriverException: disconnected: received Inspector.detached event error during test execution using Selenium and Chromedriver
Im trying to get Selenium working with Java. I'm using Maven. My pom.xml file looks like this
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.1.2</version>
</dependency>
When i try to run my programm the following error shows up. Chrome starts but does not open any sites. Ive tried chrome webdriver version 98 97 and 96. Does my normal chrome version matter?
Starting ChromeDriver 97.0.4692.71 (adefa7837d02a07a604c1e6eff0b3a09422ab88d-refs/branch-heads/4692#{#1247}) on port 61659
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
[1644353402.048][WARNING]: This version of ChromeDriver has not been tested with Chrome version 98.
Feb. 08, 2022 9:50:02 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Feb. 08, 2022 9:50:02 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 98, so returning the closest version found: 97
Feb. 08, 2022 9:50:02 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
INFO: Found CDP implementation for version 98 of 97
Sadly, Selenium 4.1.2 doesnt support v98 yet. Here is the changelog:
v4.1.2
Supported CDP versions: 85, 95, 96, 97
Add new desktop cast command for Chromium
...
This doesnt mean though that it wont work, in my case, it works perfectly. But yeah you may experience some stuff not working.
This error message...
[1644353402.048][WARNING]: This version of ChromeDriver has not been tested with Chrome version 98.
Feb. 08, 2022 9:50:02 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Feb. 08, 2022 9:50:02 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 98, so returning the closest version found: 97
Feb. 08, 2022 9:50:02 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
INFO: Found CDP implementation for version 98 of 97
...implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. google-chrome session.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
You are using chrome=98
Release Notes of ChromeDriver v98.0 clearly mentions the following:
Supports Chrome version 98
But you are using chromedriver=97.0.4692.71
Release Notes of chromedriver=97.0.4692.71 clearly mentions the following :
Supports Chrome version 97
So there is a clear mismatch between chromedriver=97.0 and the chrome=98.0
Solution
Ensure that:
Selenium is upgraded to current released Version 4.1.2.
ChromeDriver is updated to current ChromeDriver v98.0 level.
Chrome Browser is updated to current chrome=98 (as per chromedriver=98.0.4758.48 release notes).
Adding this dependency fixed the issue for me:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-devtools-v97</artifactId>
<version>4.1.2</version>
</dependency>
Keep in mind Chrome update or selenium java update might require version update of the dependency too.
Below is a snippet of code I'm using to initialize chrome webdriver:
System.out.println("Initializing Chrome");
ChromeOptions options = new ChromeOptions();
//options.setBinary("C:/Program Files (x86)/Google/Chrome/Application");
options.addArguments("start-maximized");
options.setExperimentalOption("excludeSwitches",new String[]{"enable-automation"});
options.addArguments("--disable-extensions");
options.addArguments("--disable-infobars");
options.addArguments("--allow-running-insecure-content");
WDriver = new ChromeDriver(options);
//WDriver = new ChromeDriver();
WDriver.manage().timeouts().implicitlyWait(60,TimeUnit.SECONDS);
System.out.println("Chrome Initialization Complete");
But it seems to be opening two instances of chrome, this is displayed on the console:
Initializing Chrome
Starting ChromeDriver 78.0.3904.70 (edb9c9f3de0247fd912a77b7f6cae7447f6d3ad5-refs/branch-
heads/3904#{#800}) on port 12262
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious
code.
Nov 04, 2019 3:29:38 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
log4j:WARN No appenders could be found for logger
(org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
[1572910181.451][WARNING]: Timed out connecting to Chrome, retrying...
Nov 04, 2019 3:29:43 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Falling back to original OSS JSON Wire Protocol.
[1572910186.002][WARNING]: Timed out connecting to Chrome, retrying...
Nov 04, 2019 3:29:48 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Chrome Initialization Complete
Chrome Version: 78.0.3904.87
Chromedriver Version: chromedriver_78.0.3904.70
Selenium Version: 3.141.59
While the issue is not a major roadblock it is a bit annoying that it opens a 2nd instance of chrome that will eat memory while it is on standby.
Cheers.
There are a couple of things you need to take care:
This error message...
Nov 04, 2019 3:29:38 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.
As per the discussion Attempting bi-dialect session, assuming Postel's Law holds true on the remote end thread 'webdriver dispatcher' panicked at 'index out of bounds: the len is 0 but the index is 0 this issue was observed with Selenium Client v3.0.0-beta3 which was released on 2016-09-01 14:57:03 -0700.
Simon in a comment mentioned that:
The root cause was a ClassCastException. We now catch that exception, log the thing that we were trying to parse and continue with other attempts to complete the handshake. The fix was available in Selenium Client v3.0.0-beta4.
The most appropriate solution would have been to:
Upgrade Selenium to current level of Version 3.141.59.
You can find a detailed discussion in org.openqa.selenium.remote.ProtocolHandshake createSession INFORMATION: Attempting bi-dialect session with Selenium Grid
The next error message...
Nov 04, 2019 3:29:43 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Falling back to original OSS JSON Wire Protocol.
[1572910186.002][WARNING]: Timed out connecting to Chrome, retrying...
Nov 04, 2019 3:29:48 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
...also implies that the ChromeDriver/Chrome Browser combo you are using is not the recent one as the current implementation of ChromeDriver follows W3C and initial logs are as follows:
Starting ChromeDriver 78.0.3904.70 (edb9c9f3de0247fd912a77b7f6cae7447f6d3ad5-refs/branch-heads/3904#{#800}) on port 9626
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Nov 05, 2019 3:41:53 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Solution
Ensure that:
JDK is upgraded to current levels JDK 8u222.
Selenium is upgraded to current levels Version 3.141.59.
ChromeDriver is updated to current ChromeDriver v78.0 level.
Chrome is updated to current Chrome Version 78.0 level. (as per ChromeDriver v78.0 release notes)
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
(WindowsOS only) Use CCleaner tool to wipe off all the OS chores before and after the execution of your Test Suite.
(LinuxOS only) Free Up and Release the Unused/Cached Memory in Ubuntu/Linux Mint before and after the execution of your Test Suite.
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 non-root user.
Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
References
You can find some relevant discussion in:
Issue 1504: Unable to Open latest chrome using latest Selenium.
Issue 1451: Chrome 54+ session not created exception: Runtime.executionContextCreated has invalid 'context'
Outro
As per this jar-download.com article the createSession() in ProtocolHandshake.java file of Selenium v3.0.1 contained the following:
public Result createSession(HttpClient client, Command command)
throws IOException {
// Avoid serialising the capabilities too many times. Things like profiles are expensive.
Capabilities desired = (Capabilities) command.getParameters().get("desiredCapabilities");
desired = desired == null ? new DesiredCapabilities() : desired;
Capabilities required = (Capabilities) command.getParameters().get("requiredCapabilities");
required = required == null ? new DesiredCapabilities() : required;
String des = new BeanToJsonConverter().convert(desired);
String req = new BeanToJsonConverter().convert(required);
// Assume the remote end obeys the robustness principle.
StringBuilder parameters = new StringBuilder("{");
amendW3CParameters(parameters, des, req);
parameters.append(",");
amendOssParamters(parameters, des, req);
parameters.append("}");
LOG.info("Attempting bi-dialect session, assuming Postel's Law holds true on the remote end");
Optional result = createSession(client, parameters);
// Assume a fragile OSS webdriver implementation
if (!result.isPresent()) {
parameters = new StringBuilder("{");
amendOssParamters(parameters, des, req);
parameters.append("}");
LOG.info("Falling back to original OSS JSON Wire Protocol.");
result = createSession(client, parameters);
}
// Assume a fragile w3c implementation
if (!result.isPresent()) {
parameters = new StringBuilder("{");
amendW3CParameters(parameters, des, req);
parameters.append("}");
LOG.info("Falling back to straight W3C remote end connection");
result = createSession(client, parameters);
}
if (result.isPresent()) {
Result toReturn = result.get();
LOG.info(String.format("Detected dialect: %s", toReturn.dialect));
return toReturn;
}
throw new SessionNotCreatedException(
String.format(
"Unable to create new remote session. " +
"desired capabilities = %s, required capabilities = %s",
desired,
required));
}
I'm using Selenium 3.4, Geckodriver 0.17.
I launch FirefoxDriver using the below code
System.setProperty("webdriver.gecko.driver", "geckodriver.exe");
FirefoxDriver driver = new FirefoxDriver();
driver.get("http://www.bing.com");
System.out.println(driver.getSessionId());
Is there a way I can get the IP and the port of the launched driver instance?
The data I want is printed in the logs.
1499170600204 geckodriver INFO Listening on 127.0.0.1:38840
1499170601127 geckodriver::marionette INFO Starting browser C:\Program Files\Mozilla Firefox\firefox.exe with args ["-marionette"]
[GFX1]: Potential driver version mismatch ignored due to missing DLLs igd10umd32 v= and igd10iumd32 v=
1499170608388 Marionette INFO Listening on port 12793
Jul 04, 2017 5:46:48 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
The First line of the output 127.0.0.1:38840 prints the info I want. I don't want to parse the log as I will be running drivers in parallel.
The RemoteWebDriver has getCommandExecutor method.
Which can be TypeCasted to HttpCommandExecutor and getAddressOfRemoteServer() method returns the URL.
HttpCommandExecutor ce = (HttpCommandExecutor) driver.getCommandExecutor();
System.out.println(ce.getAddressOfRemoteServer());
Does anyone have a solution for this problem?
The driver is instantiated and the browser is opened, but then I get the following error:
[01:53:15,339] INFO [CheckOut-0] - ####### Test 'MyTestCases.CheckOut' started
Starting ChromeDriver (v2.9.248304) on port 17682
May 26, 2017 1:53:16 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
[0.183][WARNING]: PAC support disabled because there is no system implementation
May 26, 2017 1:53:18 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
[01:53:20,832] INFO [CheckOut-0] - ####### Test 'MyTestCases.CheckOut' finished after 5491 ms
[01:53:20,838] INFO [CheckOut-0] - Cleaning up ...
enter image description here
I found Solution for the Problem. I had Old Libraries and replaced it with Selenium Libraries from Here and it worked.