Clear () and SendKeys () in a single method

-1

I have methods clear and sendKeys and wanted "colapsar" both in one,

WebElement user = webdriver.findElement(By.id("username"));
user.clear();
user.sendKeys(username);       
WebElement passw = webdriver.findElement(By.id("password"));
passw.clear();
passw.sendKeys(password);
    
asked by anonymous 05.12.2017 / 12:13

2 answers

1

You can create a new method:

public void setNewInputValue(WebElement elem, String value) {
    elem.clear();
    elem.sendKeys(value);
}
    
03.01.2018 / 21:38
0

There are 2 options I know, but I believe the best alternative really is to create a method for action, as shown below:

@Test
public void clearSendTest() throws InterruptedException {
    driver.findElement(By.cssSelector("input[title='pesquisar']")).sendKeys(Keys.CLEAR, "php");
    Thread.sleep(3000);
}

public void clearAfterSend() {
    driver.findElement(By.cssSelector("input[title='pesquisar']")).clear();
    driver.findElement(By.cssSelector("input[title='pesquisar']")).sendKeys("java");
}

@Test
public void clearAfterSendTest() throws InterruptedException {
    clearAfterSend();
}
    
16.04.2018 / 01:48