Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Clean input fields inside a form running a Javascript function using Selenium WebDriver + Java
// pre and post conditions ignored
@Test
void cleanByJSExecutor() {
((JavascriptExecutor) driver).executeScript("document.getElementById('my-form').reset()");
driver.findElement(By.id("email")).sendKeys("new@email.com");
driver.findElement(By.id("password")).sendKeys("987654321");
driver.findElement(By.id("address")).sendKeys("Viebrug");
driver.findElement(By.id("address2")).sendKeys("1");
driver.findElement(By.id("city")).sendKeys("Utrecht");
driver.findElement(By.id("zipcode")).sendKeys("3511 AJ");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment