Clear text from textarea with selenium

后端 未结 9 1310
时光说笑
时光说笑 2020-12-02 09:13

I\'ve got some tests where I\'m checking that the proper error message appears when text in certain fields are invalid. One check for validity is that a certain textarea el

9条回答
  •  旧巷少年郎
    2020-12-02 09:45

    You can use

     webElement.clear();
    

    If this element is a text entry element, this will clear the value.

    Note that the events fired by this event may not be as you'd expect. In particular, we don't fire any keyboard or mouse events. If you want to ensure keyboard events are fired, consider using something like sendKeys(CharSequence). E.g.:

     webElement.sendKeys(Keys.BACK_SPACE); //do repeatedly, e.g. in while loop
    

    or:

     webElement.sendKeys(Keys.CONTROL + "a");
     webElement.sendKeys(Keys.DELETE);
    

提交回复
热议问题