0

I am new to Selenium. Trying following code and it works for Firefox. When I try for Safari, getting error.

package MyTestPkg; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.safari.SafariDriver; public class MyTestClass { public static void main(String[] args) { //WebDriver driver = new FirefoxDriver(); WebDriver driver =new SafariDriver(); driver.get("http://only-testing-blog.blogspot.in"); String i = driver.getCurrentUrl(); System.out.println(i); driver.close(); } } 

OSX 10.10.3 Selenium 2.46 Safari 8.0.6

ERROR

Jun 22, 2015 5:47:12 PM org.openqa.selenium.safari.SafariDriverServer start INFO: Server started on port 43288 Jun 22, 2015 5:47:12 PM org.openqa.selenium.safari.SafariDriverCommandExecutor start INFO: Launching Safari Jun 22, 2015 5:47:12 PM org.openqa.selenium.safari.SafariDriverCommandExecutor start INFO: Waiting for SafariDriver to connect Jun 22, 2015 5:47:14 PM org.openqa.selenium.safari.SafariDriverChannelHandler$1 operationComplete INFO: Connection opened Jun 22, 2015 5:47:14 PM org.openqa.selenium.safari.SafariDriverCommandExecutor start INFO: Driver connected in 1998 ms Jun 22, 2015 5:47:14 PM org.openqa.selenium.safari.SafariDriverCommandExecutor stop INFO: Shutting down Jun 22, 2015 5:47:14 PM org.openqa.selenium.safari.SafariDriverCommandExecutor stop INFO: Closing connection Jun 22, 2015 5:47:14 PM org.openqa.selenium.safari.SafariDriverCommandExecutor stop INFO: Stopping Safari Jun 22, 2015 5:47:14 PM org.openqa.selenium.safari.SafariDriverCommandExecutor stop INFO: Stopping server Jun 22, 2015 5:47:14 PM org.openqa.selenium.safari.SafariDriverServer stop INFO: Stopping server Jun 22, 2015 5:47:14 PM org.openqa.selenium.safari.SafariDriverCommandExecutor stop INFO: Shutdown complete 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: '2.46.0', revision: '87c69e2', time: '2015-06-04 16:17:10' System info: host: 'Lajeeshs-MacBook-Pro.local', ip: '192.168.1.224', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.3', java.version: '1.8.0_45' Driver info: driver.version: SafariDriver at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:242) at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:128) at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:141) at org.openqa.selenium.safari.SafariDriver.<init>(SafariDriver.java:58) at org.openqa.selenium.safari.SafariDriver.<init>(SafariDriver.java:42) at MyTestPkg.MyTestClass.main(MyTestClass.java:10) Caused by: java.lang.ClassCastException: com.google.gson.JsonObject cannot be cast to java.lang.String at org.openqa.selenium.remote.JsonToBeanConverter.convert(JsonToBeanConverter.java:111) at org.openqa.selenium.remote.JsonToBeanConverter.convert(JsonToBeanConverter.java:42) at org.openqa.selenium.safari.SafariDriverCommandExecutor.execute(SafariDriverCommandExecutor.java:191) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:578) ... 6 more 

Any pointer how to fix this problem.

1
  • Can you please provide your drivers deatails along with safari version ? Commented Apr 9, 2020 at 20:15

1 Answer 1

0

The error message says it all:

Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. 

In this case, unless you had a network glitch that didn't allow you to access the website, it is the latter - i checked the URL and it is working fine.

So the error lies with the Safari browser.

Note that running your Selenium tests on a different browser tends to require additional setup.

You could try manually installing the Safari Driver as described here if it is actually installed.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi Laurentiu, I have tried the code on Firefox and it works fine. When I try the code for Safari, it is launching the Safari browser then crashes immediately.
@Umasankar Check the safari error logs and update your question. Ex. discussions.apple.com/thread/4439369

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.