Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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, "http://www.dunnowhattodo.org"); 

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

like image 965
Bartosz Wyględacz Avatar asked Jul 31 '13 14:07

Bartosz Wyględacz


People also ask

Can you use Selenium without a browser?

We can perform Selenium testing without a browser. This is achieved by triggering the execution in a headless mode. The headless execution can decrease the utilization of key resources and is being adopted widely.


2 Answers

Try using this method:

webdriver.get("file:///D:/folder/abcd.html"); 

(or)

selenium = new WebDriverBackedSelenium(driver, "file:///D:/folder/abcd.html"); 
like image 66
Pradeep SJ Avatar answered Sep 25 '22 19:09

Pradeep SJ


This can also be done with a relative file:

Path sampleFile = Paths.get("sample.html"); driver.get(sampleFile.toUri().toString()); 
like image 42
Synox Avatar answered Sep 24 '22 19:09

Synox