【问题标题】:How to clear a date from input type="date" with WebdriverIO如何使用 WebdriverIO 从 input type="date" 中清除日期
【发布时间】:2015-11-03 12:36:59
【问题描述】:

我现在正在使用WebdriverIO 并开发一个网络应用程序。 这些天我试图从输入 type="date" 中设置一个日期,我得到了错误

无效的元素状态:元素必须是用户可编辑的才能清除 它。

发现 我可以通过使用 addValue() 来消除错误,但任何 API 都不会清除该值。

client.clearElement('#deadline')

也得到

无效的元素状态:元素必须是用户可编辑的才能清除 它。

如何从表单中删除值?

【问题讨论】:

    标签: webdriver-io


    【解决方案1】:

    您可以在浏览器中运行脚本来清除它

    browser.execute(function () {
     document.querySelector('#deadline').value = '';
    }, null);
    

    或者给它一些价值

    var date = '2020-03-28';
    browser.execute(function (date) {
     document.querySelector('#deadline').value = date';
    }, date);
    

    参考:https://github.com/webdriverio/webdriverio/issues/386

    更优雅的方法是创建一个自定义命令并将这段代码放入其中

    【讨论】:

      【解决方案2】:

      这个对我有用:

      client.selectorExecute("#dateInput", function(inputs, value) {
          // you can run over the inputs
          for (var i = 0; i < inputs.length; i++) {
              if (inputs[i].type == 'date') // any condition
                  inputs[i].value = "1973-12-09";
          }
      
          // or just do that:
          inputs[i].value = "1973-12-09";
          return;
      })
      

      【讨论】:

        猜你喜欢
        • 2019-04-03
        • 2014-11-20
        • 1970-01-01
        • 2018-06-28
        • 1970-01-01
        • 2020-09-23
        • 2020-07-23
        • 2018-07-27
        • 2020-10-28
        相关资源
        最近更新 更多