Clear date input fails on chromewebdriver

前端 未结 5 1674
太阳男子
太阳男子 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:30
    welement.click 
    Actions action = new Actions(driver); 
    action.sendKeys(Keys.DELETE);
    action.sendKeys(webelement,value).build().perform();
    
    0 讨论(0)
  • 2021-01-01 23:32

    to clear and update the model...

         webElement.sendKeys(Keys.chord(Keys.CONTROL, "a"));
         webElement.sendKeys(Keys.BACK_SPACE);
    
    0 讨论(0)
  • 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();
    
    0 讨论(0)
  • 2021-01-01 23:35

    As a workaround you can select the webElement representing the input field and perform a

    webElement.SendKeys(Keys.Delete);

    to clear the field.

    0 讨论(0)
  • 2021-01-01 23:38

    Sometimes you can change the xpath a bit and get to the point that it works:

    For example for this piece of DOM:<tr class="table-filters"><td><input type="text" value=""></td></tr>

    if you use:

    wait.until(ExpectedConditions.visibilityOfElementLocated(By
                        .xpath("//tr[@class='table-filters']//td"))).clear();
    

    it will not work, but:

    wait.until(ExpectedConditions.visibilityOfElementLocated(By
                        .xpath("//tr[@class='table-filters']//td//input"))).clear();
    

    Works.

    0 讨论(0)
提交回复
热议问题