use*_*008 5 javascript testing angularjs protractor angular-material
我想将密钥发送到md-autocomplete,但我无法将密钥发送到文本字段,查找下面的代码
HTML:
<md-autocomplete md-selected-item="selectedItem" md-search-text="searchText" md-items="item in getMatches(searchText)" md-item-text="item.display">
<span id="xyz" md-highlight-text="searchText">{{item.display}}</span>
</md-autocomplete>
Run Code Online (Sandbox Code Playgroud)
量角器代码:
it('checking my test case', function() {
browser.get('http://localhost:8080/#/home');
var inputSearchTextBox = element(by.id("xyz"));
inputSearchTextBox.sendKeys('Boston , us , 02120');
});
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Test checking my test case
Message:
NoSuchElementError: No element found using locator: By.id("xyz")
Stacktrace:
NoSuchElementError: No element found using locator: By.id("xyz")
Run Code Online (Sandbox Code Playgroud)
角度材料链接:
有什么办法可以将密钥发送到md-autocomplete标记文本字段
小智 5
您可以使用 html 中的md-input-id属性将 id 添加到 md-input-container 中。例如 :
<md-autocomplete md-input-id="xyz" md-selected-item="selectedItem" md-search-text="searchText" md-items="item in getMatches(searchText)" md-item-text="item.display">
<span md-highlight-text="searchText">{{item.display}}</span>
</md-autocomplete>
Run Code Online (Sandbox Code Playgroud)
之后,您可以通过以下方式访问和使用它:
var myElt = element(by.css("md-autocomplete input#xyz"));
myElt.clear();
myElt.sendKeys("blabla");
Run Code Online (Sandbox Code Playgroud)