Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 745
naazneen3264 Avatar asked Oct 20 '25 03:10

naazneen3264


1 Answers

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
}
like image 51
Guy Avatar answered Oct 21 '25 18:10

Guy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!