8

how can I open a Local HTML file on my desktop using the Selenium webdriver?

I tried like below but unable to open

public static String OpenStub (String stub) {

  try {

    driver=new FirefoxDriver();
    driver.manage().timeouts().pageLoadTimeout(10000, TimeUnit.MILLISECONDS);

    driver.get("C://Users//sharmayo//Desktop//testlogin.html");

    return "Pass";
  }
}
drkthng
  • 6,651
  • 7
  • 33
  • 53
yogesh
  • 139
  • 1
  • 3
  • 10

2 Answers2

10

You should use file address like this:

driver.get("C:\\Users\\sharmayo\\Desktop\\testlogin.html");

instead of:

driver.get("C://Users//sharmayo//Desktop//testlogin.html");
jain28
  • 137
  • 5
1

Try it this way:

driver.get("file:///C:/Users/sharmayo/Desktop/testlogin.html");

UPDATE:

please first try the simplest html file like this (for your testlogin.html)

<html>
  <head>
  </head>
  <body>

    <div>Hello World!</div>

  </body>
</html>
drkthng
  • 6,651
  • 7
  • 33
  • 53
  • 1
    Not worked getting below errorFile not found Firefox can't find the file at /C:/Users/sharmayo/workspace/FodB test/Result/Result_09-08-2015 13-11-19/Screenshots/FDB-1Hit the Stub through an Appt browser.png. Check the file name for capitalization or other typing errors. Check to see if the file was moved, renamed or deleted. – yogesh Sep 08 '15 at 07:50
  • Updated my answer! ?? have you used the path for testlogin.html? what's inside your testlogin.html pls provide the code, maybe you are linking to a resource that is not there anymore -> first use the simplest possible html inside the testlogin.html – drkthng Sep 08 '15 at 08:05