clear method

  1. @override
Future<Null> clear({
  1. bool focusBefore = true,
  2. bool blurAfter = true,
})
override

WebDriver clear spec always performs a focus event and a blur event, which contradict with Pageloader clear API. Instead of using the clear API, we send a CTRL-A, then Backspace key and an empty string.

Implementation

@override
Future<Null> clear({bool focusBefore = true, bool blurAfter = true}) async =>
    _retryWhenStale(() async {
      if (focusBefore) await focus();
      _single.driver.keyboard.sendChord([sync_wd.Keyboard.control, 'a']);
      _single.driver.keyboard.sendChord([sync_wd.Keyboard.backSpace]);

      // Some elements do not support `back space`, and some elements'
      // [innerText] is detached from themselves, so we send an empty string
      // in case the above method does not work.
      _single.driver.keyboard.sendChord([sync_wd.Keyboard.control, 'a']);
      _single.sendKeys('');
      if (blurAfter) await blur();
    });