Skip to content

Instantly share code, notes, and snippets.

@eliasnogueira
Created December 19, 2020 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eliasnogueira/a81dda30c46b8531424180338df4b5bd to your computer and use it in GitHub Desktop.
Save eliasnogueira/a81dda30c46b8531424180338df4b5bd to your computer and use it in GitHub Desktop.
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