selenium web driver Unreachable browser exception with Safari on Mac - java

I have written simple code to open safari web browser in eclipse with selenium web driver on mac .also where to look for safari exe and where to place it on mac plzz help.thanks
package sanityTest;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.safari.SafariDriver;
public class AdminLogin {
public static void main(String[]args){
WebDriver driver=new SafariDriver();
//driver.close();//close the browser
}
}
I am getting this error
strong textError below
Sep 24, 2016 1:22:31 AM org.openqa.selenium.safari.SafariDriverServer start
INFO: Server started on port 3897
Sep 24, 2016 1:22:31 AM org.openqa.selenium.safari.SafariDriverCommandExecutor start
INFO: Launching Safari
Sep 24, 2016 1:22:31 AM org.openqa.selenium.safari.SafariDriverCommandExecutor start
INFO: Waiting for SafariDriver to connect
Sep 24, 2016 1:22:41 AM org.openqa.selenium.safari.SafariDriverCommandExecutor stop
INFO: Shutting down
Sep 24, 2016 1:22:41 AM org.openqa.selenium.safari.SafariDriverCommandExecutor stop
INFO: Stopping Safari
Sep 24, 2016 1:22:41 AM org.openqa.selenium.safari.SafariDriverCommandExecutor stop
INFO: Stopping server
Sep 24, 2016 1:22:41 AM org.openqa.selenium.safari.SafariDriverServer stop
INFO: Stopping server
Sep 24, 2016 1:22:41 AM org.openqa.selenium.safari.SafariDriverCommandExecutor stop
INFO: Shutdown complete
Sep 24, 2016 1:22:41 AM org.openqa.selenium.safari.SafariDriverCommandExecutor stop
INFO: Shutting down
Sep 24, 2016 1:22:41 AM org.openqa.selenium.safari.SafariDriverCommandExecutor stop
INFO: Stopping server
Sep 24, 2016 1:22:41 AM org.openqa.selenium.safari.SafariDriverCommandExecutor stop
INFO: Shutdown complete
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Failed to connect to SafariDriver after 10080 ms
Build info: version: 'unknown', revision: 'c7b525d', time: '2016-09-01 14:52:30 -0700'
System info: host: 'Vishals-MacBook-Pro.local', ip: '192.168.0.26', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.5', java.version: '1.8.0_101'
Driver info: driver.version: SafariDriver
at org.openqa.selenium.safari.SafariDriverCommandExecutor.start(SafariDriverCommandExecutor.java:118)
at org.openqa.selenium.safari.SafariDriver.startClient(SafariDriver.java:116)
at org.openqa.selenium.remote.RemoteWebDriver.startClient(RemoteWebDriver.java:284)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:117)
at org.openqa.selenium.safari.SafariDriver.(SafariDriver.java:78)
at org.openqa.selenium.safari.SafariDriver.(SafariDriver.java:58)
at sanityTest.AdminLogin.main(AdminLogin.java:10)

The Safari WebDriver on Mac OS currently requires that you compile, sign, and install a specific WebDriver browser extension as detailed here. This requires that you sign up for a free Apple developer account and get a test key to sign the extension.
Fortunately, this method of remotely automating the Safari browser is currently undergoing a transition. With the upcoming release of Safari 10, the Webkit developers are building in native WebDriver support to the Safari browser itself. In my opinion, the easiest way to currently automate Safari is to download the Safari Technology Preview and then use the current snapshot version of Selenium to launch the WebDriver. You can find instructions on how to use Safari's new WebDriver features here.

I was also facing issues in initiating safari browser on mac machine, and below solution helped me. Everytime I was calling driver init, browser was getting opened but the URL was not getting hit. I am using Page object factory, with selenium , Java , maven and testng.
if (browserType.equals("safari")) {
// System.setProperty("webdriver.safari.driver", workingDir +
// "//driver//SafariDriverServer.exe");
System.setProperty("webdriver.safari.driver",
"/driver/SafariDriver.safariextz");
System.setProperty("webdriver.safari.noinstall", "true");
DesiredCapabilities desiredCapabilities = DesiredCapabilities
.safari();
SafariOptions safariOptions = new SafariOptions();
safariOptions.setUseCleanSession(true);
safariOptions.getUseCleanSession();
safariOptions.setUseCleanSession(true);
desiredCapabilities.setCapability(SafariOptions.CAPABILITY,
safariOptions);
// deleteCookies();
driver = new EventFiringWebDriver(new SafariDriver());
ThreadDriver.set(driver);
// driver.manage().window().setSize(new Dimension(1024, 850));
getDriver().manage().timeouts().implicitlyWait(3,
TimeUnit.SECONDS);
wait = new WebDriverWait(driver, 30);
}

Related

Exception in thread "main" org.openqa.selenium.WebDriverException: Returned value cannot be converted to WebElement: {stacktrace=Backtrace:

I am getting an error in simple program, earlier it was working fine, now for some reason I am not able to execute it.
I am using selenium 3.0.1
Chrome driver 93.0.4
Please check my code and error below.
It would be appreciated if anyone can help me
My Code:
public class MouseOverDemo {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\SeleniumJars\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
// JavascriptExecutor js = (JavascriptExecutor)driver;
//driver.get("http://demo.guru99.com/test/drag_drop.html");
driver.get("https://jqueryui.com/resizable/");
Actions action = new Actions(driver);
WebElement resize = driver.findElement(By.cssSelector("body.jquery-ui.page.page-id-43.page-template-default.page-slug-resizable.single-author.singular:nth-child(2) div:nth-child(2) div.clearfix.row:nth-child(3) div.content-right.twelve.columns div:nth-child(1) > iframe.demo-frame:nth-child(5)"));
driver.switchTo().frame(resize);
WebElement resize1 = driver.findElement(By.id("resizable"));
action.moveToElement(resize1, 2500, 2500).build().perform();
System.out.println("Resize is done");
}
Error:
Starting ChromeDriver 93.0.4577.63 (ff5c0da2ec0adeaed5550e6c7e98417dac77d98a-refs/branch-heads/4577#{#1135}) on port 40273
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Nov. 11, 2021 3:43:35 P.M. org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
Nov. 11, 2021 3:43:36 P.M. org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Falling back to original OSS JSON Wire Protocol.
Nov. 11, 2021 3:43:36 P.M. org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Exception in thread "main" org.openqa.selenium.WebDriverException: Returned value cannot be converted to WebElement: {stacktrace=Backtrace:
Ordinal0 [0x003CD403+2479107]
Ordinal0 [0x00367D51+2063697]
Ordinal0 [0x00271F90+1056656]
Ordinal0 [0x00291A80+1186432]
Ordinal0 [0x002B58E7+1333479]
Ordinal0 [0x002B395A+1325402]
Ordinal0 [0x002B351D+1324317]
Ordinal0 [0x00254D3F+937279]
Ordinal0 [0x00255246+938566]
Ordinal0 [0x00255521+939297]
GetHandleVerifier [0x0054F3F6+1531734]
GetHandleVerifier [0x005FE9AE+2249998]
GetHandleVerifier [0x004539AB+501003]
GetHandleVerifier [0x00452A29+497033]
Ordinal0 [0x0036D11D+2085149]
Ordinal0 [0x00254ADE+936670]
Ordinal0 [0x002546C0+935616]
GetHandleVerifier [0x00625E4C+2410924]
BaseThreadInitThunk [0x765AFA29+25]
RtlGetAppContainerNamedObjectPath [0x777A7A9E+286]
RtlGetAppContainerNamedObjectPath [0x777A7A6E+238]
, error=invalid session id, message=invalid session id}
Build info: version: 'unknown', revision: '1969d75', time: '2016-10-18 09:43:45 -0700'
System info: host: 'DESKTOP-HAH9N6P', ip: '172.16.12.8', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.11'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:375)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByName(RemoteWebDriver.java:449)
at org.openqa.selenium.By$ByName.findElement(By.java:303)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:360)
at demoSelenium.Locators.main(Locators.java:21)
Caused by: java.lang.ClassCastException: class com.google.common.collect.Maps$TransformedEntriesMap cannot be cast to class org.openqa.selenium.WebElement (com.google.common.collect.Maps$TransformedEntriesMap and org.openqa.selenium.WebElement are in unnamed module of loader 'app')
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:373)
4 more
This error message...
Starting ChromeDriver 93.0.4577.63 (ff5c0da2ec0adeaed5550e6c7e98417dac77d98a-refs/branch-heads/4577#{#1135}) on port 40273
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Nov. 11, 2021 3:43:35 P.M. org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
Nov. 11, 2021 3:43:36 P.M. org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Falling back to original OSS JSON Wire Protocol.
Nov. 11, 2021 3:43:36 P.M. org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Exception in thread "main" org.openqa.selenium.WebDriverException: Returned value cannot be converted to WebElement: {stacktrace=Backtrace:
Ordinal0 [0x003CD403+2479107]
...implies that the ChromeDriver was unable to initiate/spawn a new Google Chrome Browsing Context.
Your main issue is the incompatibility between the version of the binaries you are using. Though you are using one of the recent ChromeDriver v93.0.4577.63 but Selenium version is 3.0.1 which is old and ancient.
Solution
Ensure that:
JDK is upgraded to current levels JDK 8u311.
Selenium is upgraded to current levels Version 4.0.0.
ChromeDriver is updated to current ChromeDriver v95.0 level.
Chrome is updated to current Chrome Version 95.0 level. (as per ChromeDriver v78.0 release notes)
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.

Having java.nio.file.FileSystemException issue while running my code using Selenium 3.4.0

While running the below code, I am getting the below error. This code is working fine with Selenium 2.53.1
Browser details:
Chrome - Version 59.0.3071.115 (64-bit)
Chrome driver - 2.30
Below code works perfectly with normal Java project. Facing issue with Maven Project only.
public class TestSel {
public static void main(String[] args) {
System.setProperty("WebDriver.chrome.driver", "chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://gmail.com");
driver.manage().window().maximize();
System.out.println("Testing Complete");
}
}
Error logs:
Starting ChromeDriver 2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41) on port 21042
Only local connections are allowed.
Jul 03, 2017 1:57:04 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Exception in thread "main" org.openqa.selenium.WebDriverException: java.nio.file.FileSystemException: C:\Users\vijender\AppData\Local\Temp\new-session2428533575725549690.json: The process cannot access the file because it is being used by another process.
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'LC-VIJENDERC', ip: '192.168.6.83', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_92'
Driver info: driver.version: ChromeDriver
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:91)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:250)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:236)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:137)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:184)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:171)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:124)
at rough.TestSel.main(TestSel.java:10)
Caused by: java.nio.file.FileSystemException: C:\Users\vijender\AppData\Local\Temp\new-session2428533575725549690.json: The process cannot access the file because it is being used by another process.
at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:86)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
at sun.nio.fs.WindowsFileSystemProvider.implDelete(WindowsFileSystemProvider.java:269)
at sun.nio.fs.AbstractFileSystemProvider.deleteIfExists(AbstractFileSystemProvider.java:108)
at java.nio.file.Files.deleteIfExists(Files.java:1165)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:168)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
... 8 more
The issue was my system specific. Resolved by window reset.

error: cannot find Chrome binary - Selenium OSX java Eclipse

I'm trying to launch Chrome using Selenium. I was able to apply this same code (with minor changes) to Firefox, but for some reason Chrome is not working.
It says it can't find the Chrome binary, but I have the chromedriver correctly linked to its file source.
Feedback anyone?
Code:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class scociatest1 {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "/Users/theone/Downloads/chromedriver-2");
// Create a new instance of the Chrome driver
WebDriver driver = new ChromeDriver();
//Launch the Scocia Demo Website
driver.get("https://apps.scotiabank.com/LEAP_Prototype/desktop/html/Chile_index.html#");
// Print a Log In message to the screen
System.out.println("Successfully opened the website");
}
}
Error Details:
Starting ChromeDriver 2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4) on port 33806
Only local connections are allowed.
Nov 24, 2016 4:14:02 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
Nov 24, 2016 4:14:03 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Exception in thread "main" org.openqa.selenium.NoSuchSessionException: no such session
(Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Mac OS X 10.11.6 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 15 milliseconds
Build info: version: 'unknown', revision: '1969d75', time: '2016-10-18 09:43:45 -0700'
System info: host: 'Thes-MacBook-Air.local', ip: '10.0.9.17', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.6', java.version: '1.8.0_112'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{message=unknown error: cannot find Chrome binary
(Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Mac OS X 10.11.6 x86_64), platform=ANY}]
Session ID: ede6a5a0ba4b5c7b2734be4418af439e
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:635)
at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:322)
at com.scocia.test.scociatest1.main(scociatest1.java:16)
You seem to be running your test from a Windows machine. Then your chromedriver should be an exe file --> "/Users/theone/Downloads/chromedriver-2.exe". After that, if it still doesn't work, you can check with an absolute path.

chrome is not able to run in Selenium Webdriver . i am using selenium 3.0.1 chrome v-54.0

public class sikuli {
public static void main(String[] args) throws Exception {
//Screen screen=new Screen();
//screen.click("//home//exeter//Pictures//googlechrome.png");
System.setProperty("webdriver.chrome.driver","//home//exeter//Documents//chromedriver");
WebDriver driver=new ChromeDriver();
driver.get("https://mail.google.com");
Starting ChromeDriver 2.24.417424 (c5c5ea873213ee72e3d0929b47482681555340c3) on port 11320
Only local connections are allowed.
Oct 19, 2016 10:07:22 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
Oct 19, 2016 10:08:22 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Exception in thread "main" org.openqa.selenium.NoSuchSessionException: no such session
(Driver info: chromedriver=2.24.417424 (c5c5ea873213ee72e3d0929b47482681555340c3),platform=Linux 4.4.0-43-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 9 milliseconds
Build info: version: 'unknown', revision: '350cf60', time: '2016-10-13 10:43:56 -0700'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{message=unknown error: Chrome failed to start: exited abnormally
It looks like you are running on a Linux machine, so "chromedriver" (without .exe) should be fine. Just make sure you have the latest chrome and latest chrome driver versions, and also you have the correct "chromedriver" file (the one on 64 bits).
Please check path is correct for chrome driver version
https://chromedriver.chromium.org. you need use chrome driver according to which chrome browser version are using
If you are running on windows you need to specify .exe at the end too(Unless you are running on Linux)
On a side note try this https://github.com/bonigarcia/webdrivermanager. It will automatically download the driver for you based on your browser and OS. Managing the driver manually is just a waste of time in my opinion.

Selenium getting error

This is my selenium test script.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class Adminlogin {
public static void main(String[] args) {
//File file = new File("C:/Selenium/IEDriverServer_x64_2.53.1/IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", "C:/Selenium/IEDriverServer_x64_2.53.1/IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
//driver.close(); //Closes the browser
}
}
I am getting this error,
Started InternetExplorerDriver server (64-bit)
2.53.1.0
Listening on port 35197
Only local connections are allowed
Oct 07, 2016 9:54:51 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
Oct 07, 2016 9:54:52 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Falling back to straight W3C remote end connection
Oct 07, 2016 9:54:52 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Falling back to original OSS JSON Wire Protocol.
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: 'unknown', revision: 'c7b525d', time: '2016-09-01 14:52:30 -0700'
System info: host: 'user-PC', ip: '192.168.2.113', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_31'
Driver info: driver.version: InternetExplorerDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:618)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:242)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:228)
at org.openqa.selenium.ie.InternetExplorerDriver.run(InternetExplorerDriver.java:180)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:172)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:144)
at Sanitytests.Adminlogin.main(Adminlogin.java:13)
Caused by: org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{ensureCleanSession=true, browserName=internet explorer, version=, platform=WINDOWS}], required capabilities = null
Build info: version: 'unknown', revision: 'c7b525d', time: '2016-09-01 14:52:30 -0700'
System info: host: 'user-PC', ip: '192.168.2.113', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_31'
Driver info: driver.version: InternetExplorerDriver
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:80)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:597)
Well, I had a simmilar error, due to SessionNotCreatedException, caused by DesiredCapabilities discrepancy.
On further research, I went back to https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver. In the "Required Configuration" section was my solution:
"Additionally, "Enhanced Protected Mode" must be disabled for IE 10 and higher. This option is found in the Advanced tab of the Internet Options dialog."
So, I went to Tools -> Internet Options -> Advanced Settings -> Security section.
Unchecked "Enable enhanced protected mode". Bingo!
I recommend you go through the "Required Configuration" section in the github link above. There might be other settings you need to apply.
I realized that IE browser capabilities had to be changed to support selenium. like zoom, protected mode, etc ...
try changing IE settings and it should work.

Categories