简体   繁体   中英

How to clear values filled in the input by JS using Selenium WebDriver?

So for the sake of learning, I am trying to automate the search process in Expedia.com my code selects "bundle deals", then "flight+Hotel+Car" then starts entering values. (depending on your location, you might see different sets of panels)

The problem is, I'm trying to automate the departure and arrival date by selecting them and inserting a date in mm/dd/yyyy format. Everything goes perfectly until it tries to input the date in returning date. It inputs the date, and then JS changes the date back, and my test fails.

public void selectDepartingDate(String date)
 {
     WebElement dte= driver.findElement(departDate);
     dte.sendKeys(date);


 }

 public void selectReturningDate(String date)
 {
     driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
     WebElement dte= driver.findElement(arrivalDate);

     dte.sendKeys(date);


 }

How exactly can i solve this?

It seems you need to click and clear it before sendKeys:

public void selectReturningDate(String date)
{
    WebElement dte= driver.findElement(arrivalDate);
    det.click();
    dte.clear();
    dte.sendKeys(date);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM