Jonathan
Jonathan

Reputation: 395

Protractor element not visible input field

Hi my issue is that i keep getting message, "element not visible" in protractor. I simply want it to find the input field and sendKeys to it and it is not working. This whole project site is done in angualrJS I even have browser.ignoreSynchronization = true; set. Any suggestions.

HTML Code

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

Upvotes: 0

Views: 804

Answers (1)

Optimworks
Optimworks

Reputation: 2547

You can use protractor.ExpectedConditions to check whether an element visible or not before going to send input to it. You can follow the below code:

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

Upvotes: 2

Related Questions