Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open A Local HTML file using selenium webdriver [duplicate]

Tags:

java

selenium

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";
  }
}
like image 936
yogesh Avatar asked Sep 08 '15 06:09

yogesh


People also ask

How can the WebDriver imitate the double click?

We can perform double click on elements in Selenium with the help of Actions class. In order to perform the double click action we will use moveToElement() method, then use doubleClick() method. Finally use build().

Can you mock in Selenium?

While you can't make the Firefox or Chrome web drivers for Selenium tests run any faster, you can create a mock version of your web application that responds lightning fast, allows front-end developers to do functional testing continuously and prevents failed test runs or slow Selenium scripts from delaying releases.

Can Selenium read HTML?

Selenium is a Python module for browser automation. You can use it to grab HTML code, what webpages are made of: HyperText Markup Language (HTML).


2 Answers

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");
like image 127
jain28 Avatar answered Sep 25 '22 10:09

jain28


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>
like image 33
drkthng Avatar answered Sep 28 '22 10:09

drkthng