Published 02 Sep, 2022

Java - How to use Selenium WebDriver on local webpage (on my PC) instead of one located somewhere online?

Category Java
Modified : Sep 29, 2022

I want to use Selenium WebDriver on a webpage that I have on my hard disc. I've tried to something like:

selenium = new WebDriverBackedSelenium(driver, "C:\\...dispatcher.html");

...instead of the normal:

selenium = new WebDriverBackedSelenium(driver, "");

...but it doesn't work (I get the error "unknown protocol: c").


There are 4 suggested solutions here and each one has been listed below with a detailed description. The following topics have been covered briefly such as Url, Java, Selenium Webdriver, Path. These have been categorized in sections for a clear and precise explanation.


Try using this method:



selenium = new WebDriverBackedSelenium(driver, "file:///D:/folder/abcd.html");


When you call the driver.get(URL) method, WebDriver looks for HTTP request using as base javascript, Therefore, refering to a website as a path, that task won't be possible.

But it will be possible if you : 1st- Install Apache WebServer (let's say) on your marchine. 2nd- Upload or expose to the WebServer, that web application (dispatcher.html) 3rd- Try recording and executing your testcases on [http://localhost:8080/dispatcher.html] (8080 is the default port but you can configure it to other).


You can always drag and drop html file from your PC on open web browser during selenium session and see how file path looks. In my case it is:



Selenium Version: 3.141.59

Use this webdriver.get("file:///D:/folder/abcd.html") get failed.

Instead of webdriver.get("///D:/folder/abcd.html") get successfully.