Selenium Java to clear and enter the value in an input field
KW.java
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

class KW
{
    public static void main(String[] args) 
    {   
        System.setProperty("webdriver.chrome.driver", "/home/kodingwindow/drivers/chromedriver");
        WebDriver driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.get("https://kodingwindow.com/testapp/");
        driver.findElement(By.name("username")).sendKeys("USERNAME");
        driver.findElement(By.name("username")).clear();
        driver.findElement(By.name("username")).sendKeys("kodingwindow");
        driver.findElement(By.name("password")).sendKeys("kodingwindow");
        driver.findElement(By.name("login")).click();
        driver.close();
    }
}
Advertisement