-3

Why in get() method of FirefoxDriver() driver I need to mention http:// E.g,driver.get("http://www.example.com"); if I dont provide http then I am getting an error.Why get() method needs http://.

public class OpenBrowser{

public void clickAddUser(){
    WebDriver d = new FirefoxDriver();
    d.get("www.example.com");

}

public static void main(String[] args) {
    OpenBrowser o =new OpenBrowser();
    o.clickAddUser();
}

Exception in thread "main" org.openqa.selenium.WebDriverException: Target URL www.example.com not well-formed. Command duration or timeout: 59 milliseconds

  • 6
    Because a URL requires a protocol. You are simply not used to it because browsers do that work for you when you surf the interwebz. – f1sh Jun 13 '18 at 15:48
  • 1
    How would you driver know the protocol (http, https or other) otherwise? – Ahmad Shahwan Jun 13 '18 at 15:48

1 Answers1

0

As per the Selenium Java Client get is defined in DriverCommand interface as:

String GET = "get";

The implementation of get() method works pretty much similar.

As an example from the Selenium Python Client get() method is defined as:

def get(self, url):
    """
    Loads a web page in the current browser session.
    """
    self.execute(Command.GET, {'url': url})

So, Command.GET requires an argument of type url

As per wikipedia URL is the Uniform Resource Locator (URL) is a reference to a web resource that specifies its location on a computer network and a mechanism for retrieving it. A URL is a specific type of Uniform Resource Identifier (URI). URLs occur most commonly to reference web pages (http), but are also used for file transfer (ftp), email (mailto), database access (JDBC), and many other applications.

Most web browsers display the URL of a web page above the page in an address bar. A typical URL could have the form http://www.example.com/index.html which indicates a protocol (e.g. http), a hostname (e.g. www.example.com), and a file name (e.g. index.html).

hence you need to specify all the three arguments as mentioned above.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352