量角器元素不可见输入字段

时间:2016-08-30 14:54:06

标签: javascript angularjs protractor automated-tests

您好我的问题是我在量角器中不断收到消息,“元素不可见”。我只是想让它找到输入字段并将sendKeys发送给它并且它不起作用。整个项目站点在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
  });
});

1 个答案:

答案 0 :(得分:2)

您可以使用protractor.ExpectedConditions检查元素是否可见,然后再向其发送输入。您可以按照以下代码:

var EC=protractor.ExpectedConditions;

 describe('New stack hompage test', function() {
    beforeEach(function(){
       browser.get('http://localhost:3000/');
     });
    it('should test search form', function() {
      var search =  
              element.all(by.css("input[name='search_query']")).first();
      expect(browser.getTitle()).toEqual('Find Homes for Sale, Rent & Real 
                                Estate Listings Nationwide at Homes.com');
      browser.wait(EC.visibilityOf(search).call(),8000,'search filed not 
                                                          visible');
      search.sendKeys('anything');
    });
});