Selenium WebDriver. Open local file

This is going to be short one. Let’s place some html file into resources folder in your project (test or main).

Open local file

Now we want to open the local file using Selenium WebDriver and click on the button for example.

String path = this.getClass().getResource("/my-local-form-page.html").getPath();
driver.get("file://" + path);
driver.findElement(By.id("button")).click();

You may also find these posts interesting: