1

I'm trying to get a url using selenium-java 3.3.1 and when I do the following:

driver.get(url.toString())

Where the URL looks like this:

https://hello.world.io/@snapshot/web/1.23.207-1-gc2b81d1/?referrer=/beta

Selenium only enters everything after the @ into the url of my ChromeBrowser. I've tried URLEncoding the entire URL and only the portion after and containing the @ but that gives me an invalid url error.

Would appreciate and help trying to force selenium-java to navigate to that url.

EDIT

I tried doing

driver.get("https://hello.world.io/@snapshot/web/1.23.207-1-gc2b81d1/?referrer=/beta");

and that works.

But I need to pass in the URL as a variable which I'm doing and then calling .toString(). I've printed the result to toString() out to the console and it looks fine so there must be something very odd happening that I can put my finger on.

2
  • Putting that url in manually worked for me. So, doing this worked: driver.get("https://hello.world.io/@snapshot/web/1.23.207-1-gc2b81d1/?referrer=/beta"); I am guessing there is an issue with your toString() method Commented Jun 2, 2017 at 21:23
  • have you tried using driver.get(url) ?? Commented Jun 3, 2017 at 4:39

1 Answer 1

1

Here is the Answer to your Question:

Though I wasn't able to access the url of your concern https://hello.world.io/@snapshot/web/1.23.207-1-gc2b81d1/?referrer=/beta but using Selenium 3.4.0, chromedriver v2.29 & Google Chrome 58.x I have tried the following Usecases:

Usecase 1:

If the concerned url https://hello.world.io/@snapshot/web/1.23.207-1-gc2b81d1/?referrer=/beta is a Sting class object, the following code works-

String url = "https://hello.world.io/@snapshot/web/1.23.207-1-gc2b81d1/?referrer=/beta";
driver.get(url);

Usecase 2:

If the concerned url https://hello.world.io/@snapshot/web/1.23.207-1-gc2b81d1/?referrer=/beta is a URL class object, in that case you have to convert it from URL class to String class through toString() method as follows which worked for me too:

String url = "https://hello.world.io/@snapshot/web/1.23.207-1-gc2b81d1/?referrer=/beta";
URL myurl = new URL(url);
driver.get(myurl.toString());

PS: If you are using the URL class you have to import java.net.URL; which will throws MalformedURLException, so you have to import java.net.MalformedURLException;

Let me know if this Answers your Question.

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

1 Comment

usecase 2 is very similar to what I have in my own code base, but what I'm experiencing that that when I call driver.get(myurl.toString()) it only enters the portion of the string after the @ symbol.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.