naazneen3264
naazneen3264

Reputation: 315

Passing URL in selenium without http or https

I want to check whether the URL's are https or not?

For this:
I need to pass URL's without http/https.
eg: driver.get("google.com"); and driver.get("http://google.com");

Can anyone help me out please. Is it possible to automate such scenario's ?

Thanks in advance.

Upvotes: 4

Views: 6211

Answers (1)

Guy
Guy

Reputation: 50899

driver.get() requires valid URL that starts with "http"/"https". However, driver.get("http://www.google.com") will navigate to "https://www.google.com"

For the parsing you can use startsWith method

String url = driver.getCurrentUrl();
if (url.startsWith("https")) {
    // url is https
}
else {
    // url is http
}

Upvotes: 3

Related Questions