获取 textToBePresentInElementValue 长度

Get textToBePresentInElementValue length

我想检查我的隐藏输入是否包含一个值,如果没有就等到它包含。

这是因为我知道当隐藏输入有值时页面已完成加载,我想使用该值。

我试过以下方法: 这个 textToBePresentInElementValue 得到了很好的值,但我需要它等到它包含一个值。

我试过这样的事情: browser.wait(EC.textToBePresentInElementValue($('#isearchstring').lenght > 0), 5000);

但是我得到一个错误: Cannot read property 'bind' of undefined

当我的页面加载时,我的 HTML 看起来像这样:<input type="hidden" name="searchstring" id="isearchstring" value=""> 几秒钟后它可能包含任何值 <input type="hidden" name="searchstring" id="isearchstring" value="xxxxx">

我不想使用 browser.sleep();

如果你想等待一个元素有文本,你可以为它写一个函数:

const EC = protractor.ExpectedConditions;

const isTextPresent = function(elm) {
  const hasText = function() {
    return elm.getText().then(function(elmText) {
      return elmText;
    });
  };
  return EC.and(EC.presenceOf(elementFinder), hasText);
};

然后使用它:

browser.wait(isTextPresent(element(by.binding('myvar'))), 5000);

使用getAttribute('value')获取输入值(无论可见与否)

browser.wait(function(){
  return element(by.css('input#isearchstring'))
          .getAttribute('value')
          .then(function(value){
              return value !== '';
          });
}, 5000);