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

标签 html angularjs protractor

我正在使用 Protractor 运行端到端测试,但无法使用 getText() 验证元素的文本。 Protractor 返回:

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>

在我的测试脚本中,我有:

element(by.id('requesterSearchInput')).click();
browser.actions().sendKeys('Joe Smith').perform();
expect(element(by.id('requesterSearchInput')).getText()).toEqual('Joe Smith');

但是最后一行失败了:

 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');

非常感谢您的帮助。

最佳答案

据我了解,您需要检查的是 value 属性:

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

关于html - 使用 getText() 验证元素在使用 typeahead 时返回空字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29437057/

相关文章:

javascript - 网络驱动程序错误: Cannot find elements when the xpath expression is null in javascript

Protractor 如何运行单个测试用例?

selenium - 将 Protractor 直接连接到浏览器驱动程序时使用什么协议(protocol)?

html - 按钮,文本和内联元素的不同颜色,两者都应该能够在悬停时改变颜色

c# - 在 HTML 中显示 gnu diff

html - 背景图像未显示

Angularjs - 无法根据滚动位置显示/隐藏元素

javascript - Angular JS 重构 Controller 依赖注入(inject)

html - Flexbox 在手机、平板电脑和旧浏览器上的显示问题

javascript - 从外部 Angular Controller 访问变量