【发布时间】:2024-01-18 07:11:01
【问题描述】:
您好,我的问题是我不断收到消息,量角器中“元素不可见”。我只是想让它找到输入字段并向它发送密钥,但它不起作用。整个项目站点都是用 angualrJS 完成的,我什至有 browser.ignoreSynchronization = true;放。有什么建议么。
HTML 代码
input parse-search-query="" type="text" tabindex="1" name="search_query" autocomplete="off" placeholder="Search by City ST, Zip, or Address" data-ng-model="searchQueryFieldCtrl.searchFormController.searchParams.search_query" data-ng-change="searchQueryFieldCtrl.searchFormController.clearErrors()" data-focus-on="focusQuery || form.search_query.$error" data-uib-typeahead="suggestion as suggestion.label for suggestion in searchQueryFieldCtrl.getSuggestions($viewValue)" data-typeahead-focus-first="false" data-typeahead-min-length="0" data-typeahead-wait-ms="300" data-typeahead-on-select="searchQueryFieldCtrl.setSearch($item)" class="ng-pristine ng-untouched ng-valid ng-scope" aria-autocomplete="list" aria-expanded="false" aria-owns="typeahead-69-869">
spec.js
describe('New stack hompage test', function() {
it('should test search form', function() {
browser.ignoreSynchronization = true;
var flow = protractor.promise.controlFlow();
function waitOne() {
return protractor.promise.delayed(3000);
}
function sleep() {
flow.execute(waitOne);
}
browser.get('http://localhost:3000/');
sleep()
expect(browser.getTitle()).toEqual('Find Homes for Sale, Rent & Real Estate Listings Nationwide at Homes.com');
sleep()
var search = element.all(by.css("input[name='search_query']"));
sleep()
search.sendKeys('anything'); // this is not working
});
});
【问题讨论】:
-
如果它是一个角度应用程序,你为什么要设置
ignoreSynchronization = true? -
我收到同步错误
-
您是否尝试过延长超时时间?大多数超时默认为 10 秒,我认为这非常低。 timeout reference
-
Yes 扩展了 22 很多人在堆栈溢出时遇到了同样的问题,不得不将其设置为 (true)。
-
element.all 返回元素数组,因此请使用数组索引号,例如搜索[0].sendKeys('anything');
标签: javascript angularjs protractor automated-tests