Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/143.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 使用getText()验证元素在使用typeahead时返回空字符串_Html_Angularjs_Protractor - Fatal编程技术网

Html 使用getText()验证元素在使用typeahead时返回空字符串

Html 使用getText()验证元素在使用typeahead时返回空字符串,html,angularjs,protractor,Html,Angularjs,Protractor,我正在使用量角器运行e2e测试,但无法使用getText()验证元素的文本。量角器返回: Expected '' to equal 'Joe Smith'. 代码如下: <span class="input-group" style="padding: 40px;"> <input tabindex="0" class="form-control ng-valid ng-dirty ng- valid-parse ng-touched" id="requesterSear

我正在使用量角器运行e2e测试,但无法使用getText()验证元素的文本。量角器返回:

Expected '' to equal 'Joe Smith'.
代码如下:

<span class="input-group" style="padding: 40px;">
 <input tabindex="0" class="form-control ng-valid ng-dirty ng-
 valid-parse ng-touched" id="requesterSearchInput" aria-expanded="false"
 aria-invalid="false" aria-owns="typeahead-6604-1028" aria-
 autocomplete="list" type="text" placeholder="Enter a Requester name" ng-
 model="searchText" typeahead-loading="loadingLocations" typeahead-wait-
 ms="500" typeahead-min-length="1" typeahead-on-
 select="OnRequesterSelect($item)" typeahead-template-
 url="requesterTypeAheadTemplate.html" typeahead="rdata for rdatas in 
 GetRequesters($viewValue)"></input>
但是,最后一行出现以下故障:

 Expected '' to equal 'Joe Smith'.
我曾多次尝试解决这个问题,但都没有成功。以下是我的尝试:

尝试1:

expect(element(by.id('requesterSearchInput')).getText()).toEqual('Joe Smith');
尝试2:

expect(element(by.id('requesterSearchInput')).getAttribute("aria-hidden")).toEqual('Joe Smith');
尝试3:

expect(element(by.id('requesterSearchInput')).getAttribute("innerText")).
    toEqual('Joe Smith');
尝试4:

var previousEntry = element(by.xpath("//div[@ng-hide='searchText']"))
    .getAttribute("aria-hidden");
expect(previousEntry).toEqual('Masterson');

非常感谢您的帮助。

据我所知,您需要检查的是
属性:

expect(element(by.id('requesterSearchInput')).getAttribute('value')).toEqual('Joe Smith');

好吧,我误解了前面的例子。我认为我需要用和属性替换值。我按照你的建议使用了价值观,它起了作用。谢谢
expect(element(by.id('requesterSearchInput')).getAttribute('value')).toEqual('Joe Smith');