Clear date input fails on chromewebdriver

前端 未结 5 1677
太阳男子
太阳男子 2021-01-01 22:50

I ran into a problem while switching from firefoxdriver to chromedriver with selenium, it was working fine in FF but now when I try to clear a date input field I have this e

5条回答
  •  借酒劲吻你
    2021-01-01 23:33

    I have a solution to this that I have just used in my ChromeDriver project in Eclipse. It is also a work around.

    I found that simply using {webElement.Keys} only deleted part of the text in the input field. So you must first use the left arrow key to select the entire text to delete.

    The following code should work in ChromeDriver. It is in Java (using Eclipse):

    private WebDriver driver;
    driver= new ChromeDriver();
    Actions action = new Actions(driver);
    int lenText = driver.findElement(By.xpath(elementLocator)).getText().length();
    
    for(int i = 0; i < lenText; i++){
      action.sendKeys(Keys.ARROW_LEFT);
    }
    action.build().perform();
    
    for(int i = 0; i < lenText; i++){
      action.sendKeys(Keys.DELETE);
    }
    Thread.sleep(1000);
    action.build().perform();
    

提交回复
热议问题