Selenium error - Cannot navigate to invalid URL
Asked Answered
B

7

13

I get the following error :

unknown error: unhandled inspector error:
{"code":-32603,"message":"Cannot navigate to     
invalid URL"} (Session info: chrome=29.0.1547.57) (Driver info:    
chromedriver=2.2,platform=Windows NT 6.1 SP1 x86_64)

I think its got to do with chrome browser last updated version (29) about two days ago.

*Note:*my chromedriver is up to date (2.2).

please let me know what should i do to fix it.

Breezeway answered 25/8, 2013 at 13:51 Comment(2)
Please provide some more information, like about your webdriver version and the url you are using.Erskine
possible duplicate of get the following error on seleniumDirectoire
D
22

I received the same error while using Selenium on python. Prepending the destination url with http:// solved my problem:

self.driver.get("http://"+url.rstrip())
Depart answered 7/10, 2013 at 3:7 Comment(0)
C
3

This literally happens because the url you are passing in is using an invalid format.

Try the following debug code, where ourUrl is the String of the URL you are trying to connect to:

System.out.println("!!URL " +ourUrl);

driver.get(ourUrl);

for me it was printing out: !!URL "http://www.salesforce.com" And the problem was that there were quotes around the url. In your case it may be something similar. Once you properly format the url, it will work

Clover answered 20/4, 2014 at 21:42 Comment(0)
C
1

I met this error now minutes ago,but i have solved it by adding "https://" to the front of the url. Hope it works for you too.Good luck!

Carboniferous answered 11/6, 2017 at 13:2 Comment(0)
S
1

If the error message is "invalid url", check the url on the webpage that you are trying to access, then compare it to what prints out when you do something like:

System.out.println(url);

When selenium tries to open up a webpage, it needs the exact url. It wont infer the Hyper Text Transfer Protocol (http:// or https://). In other words, if you try driver.get(url), and url is returning www.myurl.com, it will likely fail if http or https was not appended.

//Append the Hyper Text Transfer Protocol to the url
driver.get("http://" + url);

If you are getting your urls from a list, or from a file, and you know which protocol your website page(s) use (http:// or https://), you can do something like:

public static void getURLByDriverFromList(List<String> urls) {
    for(List<String> url : urls) {
        if(!url.contains("http://") {
            url = "http://" + url;
        }
    driver.get(url);
    }
}
Stoddard answered 31/1, 2019 at 18:13 Comment(0)
E
0

You can use absolute path as mentioned in other comments or - if it is an internal link/button on the web - you can mapp it as WebElement and perform click() method.

Elwina answered 21/8, 2017 at 8:29 Comment(0)
M
0

I had exactly the same error but it was due to a parsing issue in Python Behave BDD.

For example, if I have the following feature syntax

Given the user is on <page> using <url>

and my examples syntax has

Examples: Pages
    | page                    | url                           |
    | Mobile App using Guide  | https://www.example.com       |

See how I have the word using between my variables in the given statement and also used using in the page title Mobile App using Guide. Because of this, the word Guide will get added on to the url and Selenium will return the invalid url error.

If you're using Behave or possibly any BDD with Gherkin syntax, avoid using the same keyword in between variables from the Given, When, Then statements in the Example table.

Melloney answered 14/11, 2017 at 0:13 Comment(0)
S
0

Try the following code, it's working for me.

WebDriver driver = new ChromeDriver();
driver.get("https://www.facebook.com");

Add https in your URL.

Shulamith answered 5/10, 2018 at 19:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.