Unable to create new remote session - Selenium webdriver - java

I am getting exception
Exception in thread "main"
org.openqa.selenium.SessionNotCreatedException: Unable to create new
remote session. desired capabilities = Capabilities [{marionette=true,
browserName=firefox, version=48.0.1, platform=ANY}], required
capabilities = Capabilities [{}]' while trying to run selenium script
in a remote web driver.
Hub and node are configured properly and its able to communicate to each other.
Selenium web driver : 3.0
Platform : Windows server 2012 R2.
Firefox Version: 48.0.1
Code used in my script :
System.setProperty("webdriver.gecko.driver", "mypath/geckodriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
capabilities.setBrowserName("firefox");
capabilities.setPlatform(Platform.ANY);
RemoteWebDriver driver =new RemoteWebDriver(new URL("http://ipofthenode:4444/wd/hub"), capabilities);
driver.get("http://stackoverflow.com");
System.out.println("executed");
Detailed stack trace:
an 19, 2017 6:07:36 PM org.openqa.selenium.remote.ProtocolHandshake
createSession INFO: Attempting bi-dialect session, assuming Postel's
Law holds true on the remote end Jan 19, 2017 6:07:37 PM
org.openqa.selenium.remote.ProtocolHandshake createSession INFO:
Falling back to original OSS JSON Wire Protocol. Jan 19, 2017 6:07:37
PM org.openqa.selenium.remote.ProtocolHandshake createSession INFO:
Falling back to straight W3C remote end connection Exception in thread
"main" org.openqa.selenium.SessionNotCreatedException: Unable to
create new remote session. desired capabilities = Capabilities
[{marionette=true, browserName=firefox, version=48.0.1,
platform=ANY}], required capabilities = Capabilities [{}] Build info:
version: '3.0.0', revision: '350cf60', time: '2016-10-13 10:48:16
-0700' System info: host: 'Hostname', ip: 'IP', os.name: 'Windows Server 2012 R2', os.arch: 'amd64', os.version: '6.3', java.version:
'1.8.0_101' Driver info: driver.version: RemoteWebDriver at
org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:91)
at
org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at
org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:241)
at
org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:128)
at
org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:155)
at demo.Grid.main(Grid.java:26)

Create a .bat file adding below command
C:\Selenium_Grid
start java -Dwebdriver.gecko.driver=C:\Selenium_Grid\geckodriver\geckodriver.exe -jar C:\Selenium_Grid\selenium-server-standalone-3.0.1.jar -role node -hub http://localhost:4444/grid/register -browser browserName=firefox -port 5555
(replace paths with yours)
then start the .bat file before executing your code

Related

Selenium in Java is not finding element when using headless Chrome

I want to find some elements from an JavaScript based website. I use Java and Selenium. Everything works fine, but when I want to use headless Chrome, then Selenium is not able to find the elements.
I added this options to my ChromeDriver:
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
Console:
ChromeDriver was started successfully.
2020-08-27 22:41:46.625 INFO 20344 --- [ null to remote] o.o.selenium.remote.ProtocolHandshake : Detected dialect: W3C
Exception in thread "Thread-8" Exception in thread "Thread-10" org.openqa.selenium.TimeoutException: Expected condition failed: waiting for presence of element located by: By.cssSelector: [data-id='current-price'] (tried for 5 second(s) with 500 milliseconds interval)
at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:95)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:272)
at magharmi.asos.pricechecker.controller.PriceController$1.run(PriceController.java:52)
Caused by: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"[data-id='current-price']"}
(Session info: headless chrome=85.0.4183.83)
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'DESKTOP-MMDJR4G', ip: '192.168.178.45', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '13.0.1'
Driver info: org.openqa.selenium.chrome.ChromeDriver
While using headless mode you need to:
Maximize the browsing window
ChromeOptions options = new ChromeOptions();
options.addArguments("--window-size=1400,600");
Instead of presenceOfElementLocated() induce WebDriverWait for visibilityOfElementLocated() as follows:
WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("[data-id='current-price']")));

Selenium unable to connect to ChromeDriver 75 on Mac

We are upgrading a previously-working Selenium/Java/Chrome test configuration, to newer versions:
ChromeDriver 2.35 -> 75.0.3770.90
Selenium Java 3.14 -> 3.141.59
macOS 10.14.5 (unchanged)
Java 11.0.3 (unchanged)
Chrome 75.0.3770.100 (unchanged)
However, when attempting to run a Selenium test, we see:
java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:28719
The full stack/log:
Starting ChromeDriver 75.0.3770.90 (a6dcaf7e3ec6f70a194cc25e8149475c6590e025-refs/branch-heads/3770#{#1003}) on port 28719
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Jun 26, 2019 10:45:03 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
...
org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:28719
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'Craigs-iMac.local', ip: '192.168.1.131', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.5', java.version: '11.0.3'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:92)
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.findElementByTagName(RemoteWebDriver.java:396)
at org.openqa.selenium.By$ByTagName.findElement(By.java:320)
All the resources I've found in this area suggest using --whitelisted-ips='', which did not have an effect, or were related to incompatible Selenium/Chrome/ChromeDriver versions, which I don't think is the issue here.
Update: I can confirm that the driver starts, and is listening on port 28719, but then stops at some point between startup and execution of the actual test. I've found no errors/logging related to the shutdown.
Update 2: I've debugged, and the initial commands sent to the remote driver succeed (setWindowSize()), but this line causes the driver to die silently:
((WebStorage) driver).getLocalStorage().setItem("token", token);
It seems newer versions of the ChromeDriver (Or Selenium? I don't know.) launch Chrome with an initial page sitting at the URL data:.
By adding these system properties prior to instantiating the ChromeDriver:
System.setProperty("webdriver.chrome.logfile", "/Users/craig/chromedriver.log");
System.setProperty("webdriver.chrome.verboseLogging", "true");
I was able to glean the following right before the driver quits:
[1561563455.971][INFO]: [01517094c63c0dd609c06a5622afe6b1] RESPONSE ExecuteScript ERROR <unknown>: Failed to read the 'localStorage' property from 'Window': Storage is disabled inside 'data:' URLs.
(Session info: headless chrome=75.0.3770.100)
So by changing this call in my test utility code:
((WebStorage) driver).getLocalStorage().setItem("token", token);
To this:
if (driver.getCurrentUrl().startsWith("data:")) {
// Driver will quit if we try to access localStorage without a page load
driver.get("/");
}
((WebStorage) driver).getLocalStorage().setItem("token", token);
Everything is now fine. https://i.imgur.com/edBQBeJ.gif
Editing:
LocalStorage is available only after launching any website. ie after driver.get
https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/html5/LocalStorage.html

Unable to run Headless Chrome Browser on Linux Machine using Selenium Webdriver java

Used Selenium Webdriver(V2.29), selenium-api version(3.4.0), Chrome
Version (62.0.3202.94) 64 bit and tried to run chrome browser in linux machine with the below code.
WebDriver driver;
String chromeBinaryPath = "/data/Package/CHROME_NEW";
String driverPath = "/data/Package/Selenium/WebDrivers/ChromeDrivers/chromedriver_linux32/chromedriver";
System.setProperty("webdriver.chrome.driver", driverPath);
System.setProperty("webdriver.chrome.verboseLogging","true");
System.setProperty("webdriver.chrome.logfile","/data/Package/log/chromedriver.log");
ChromeOptions optionsLinux64 = new ChromeOptions();
optionsLinux64.setBinary(chromeBinaryPath);
optionsLinux64.addArguments("--headless");
optionsLinux64.addArguments("--no-sandbox");
optionsLinux64.addArguments("--disable-gpu");
optionsLinux64.addArguments("--headless");
driver = new ChromeDriver(optionsLinux64);
When tried to create a chrome session, getting below exception:
unknown error: Chrome failed to start: exited abnormally (Driver info: chromedriver=2.29.461571 (8a88bbe0775e2a23afda0ceaf2ef7ee74e822cc5),platform=Linux 3.10.0-693.5.2.el7.x86_64 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 60.10 seconds Build info: version: '3.4.0', revision: 'unknown', time: 'unknown' System info: host: 'el4014.bc', ip: '10.120.94.70', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-693.5.2.el7.x86_64', java.version: '1.8.0_151' Driver info: driver.version: ChromeDriver
Installed Chrome at /data/Package/CHROME_NEW folder using rpm file.
Message in chromedriver.log:
[0.204][DEBUG]: DevTools request: http://localhost:12111/json/version
LaunchProcess: failed to execvp:
/data/Package/CHROME_NEW/
[0.379][DEBUG]: DevTools request failed
Can anyone help me in resolving with the above issue.
This should be work:
ChromeOptions options = new ChromeOptions();
options.setHeadless(true);
Try adding window size
optionsLinux64.addArguments("window-size=1024x780");

Selenium webdriver error..It is unable to send keys with selenium webdriver

I am using Selenium Webdriver. I have searched many times and tried every answer in order to successfully testing a case. I am new to test automation.
Problem: There is an error when I use .sendKeys() and also click on some web element. I am really upset about this. I want to go forward with testing. Please help me solve this.
And also it displays an error stating InvalidValueError: initMap is not a function. Previously I have ran this codes successfully.
My setup is a follows:
Firefox 53.0
Eclipse Juno 32bit
Selenium Wevdriver 3.3.1
GeckoDriver 16.0
logger apache-log4j-1.2.17
This is the error:
1495778288530 geckodriver INFO Listening on 127.0.0.1:23817
1495778289152 mozprofile::profile INFO Using profile path
C:\Users\EXTROG~1\AppData\Local\Temp\rust_mozprofile.pTb73U1lR7sv
1495778289154 geckodriver::marionette INFO Starting browser C:\Program
Files\Mozilla Firefox\firefox.exe with args []
1495778289159 geckodriver::marionette INFO Connecting to Marionette on
localhost:50245 1495778293537 Marionette INFO Listening on port 50245
May 26, 2017 11:28:13 AM org.openqa.selenium.remote.ProtocolHandshake
createSession INFO: Detected dialect: W3C JavaScript error: , line 0:
uncaught exception: InvalidValueError: initMap is not a function INFO
[main] (SearchBarTest.java:20)- search bar is there Error : Expected
[object Undefined] undefined to be a string Build info: version:
'unknown', revision: '5234b32', time: '2017-03-10 09:00:17 -0800'
System info: host: 'EXTROGENE-PC', ip: '192.168.1.18', os.name:
'Windows 7', os.arch: 'x86', os.version: '6.1', java.version:
'1.8.0_121' Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities
[{moz:profile=C:\Users\EXTROG~1\AppData\Local\Temp\rust_mozprofile.pTb73U1lR7sv,
rotatable=false, timeouts={implicit=0, pageLoad=300000, script=30000},
pageLoadStrategy=normal, platform=ANY, specificationLevel=0,
moz:accessibilityChecks=false, acceptInsecureCerts=false,
browserVersion=53.0.3, platformVersion=6.1, moz:processID=1896,
browserName=firefox, platformName=windows_nt}] Session ID:
0d78f916-fa2e-4325-8baf-08b8e444d250
This is my code:
WebElement element=driver.findElement(By.xpath("//*[#id='serchkey']"));
driver.findElement(By.xpath("//*[#id='serchkey']")).sendKeys(new String("toy"));
Try this it may work:
WebElement element =driver.findElement(By.id("serchkey"));
javascriptSendKeys(element,"toy");
private void javascriptSendKeys(WebElement yourElement, String yourText){
JavascriptExecutor executor = (JavascriptExecutor)webDriver;
executor.executorScript("arguments[0].value='" + yourText + "';", yourElement);
}
Here is the Answer to your Question:
Great job done by specifying the Test Environment details as:
Selenium Webdriver 3.3.1
GeckoDriver 16.0
Now, if you have a look at the documentation of geckodriver v0.16.0 here, you will find a Heading as: "Note that geckodriver v0.16.0 is only compatible with Selenium 3.4 and greater."
So the solution to your Question is to upgrade your Selenium to 3.4.0 from here.
Let me know if this Answers your Question.

getting error using latest chromedriver 2.28 - disconnected: received Inspector.detached event

Seem to be getting this error waiting for popup window. As I am watching the script execute the js button executes and popup window does open but my test fails with the following error:
org.openqa.selenium.WebDriverException: disconnected: received Inspector.detached event
(Session info: chrome=56.0.2924.87)
(Driver info: chromedriver=2.28.455520 (cc17746adff54984afff480136733114c6b3704b),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 3.20 seconds
Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09'
System info: host: '*******', ip: '*******', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_91'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.28.455520
This is about chrome issue(https://bugs.chromium.org/p/chromedriver/issues/detail?id=1194).
When you are running selenium program, you cannot press F12 to open dev tools manually, or it'll throw this exception sometimes. You can browse this chrome driver official page.
According to the issue list, it looks like fixed, but I still meet this bug in ChromeDriver 2.29.
Try updating your Chrome, I can see that your chromedriver version is 2.28 which is the most recent release and it should support Chrome v55-77, but updating Chrome might be a solution.

Categories

Resources