saqib
saqib

Reputation: 41

sendKeys and click() is not working. Unable to get elements and I am using protractor javascript code

<input class="form-control validation-field ng-dirty ng-touched ng-invalid" placeholder="Password" type="password">

Am using this to get the element but its not sending keys and also not showing any error message. I have tried on both Firefox and google chrome.

element.all(By.css('.form-control.validation-field.ng-dirty.ng-valid.ng-touched')).sendKeys('sample code');

This is my conf.js file

// An example configuration file.

exports.config = {
    directConnect: true,

    // Capabilities to be passed to the webdriver instance.
    capabilities: {
        'browserName': 'firefox'
    },

    // Framework to use. Jasmine is recommended.
    framework: 'jasmine',

    // Spec patterns are relative to the current working directory when
    // protractor is called.
    specs: ['example_spec.js'],

    // Options to be passed to Jasmine.
    jasmineNodeOpts: {
        defaultTimeoutInterval: 100000
    }
};

If I use get(0) or get(1) its showing error that cannot locate using this css . Why?

Upvotes: 4

Views: 812

Answers (3)

Silvan Bregy
Silvan Bregy

Reputation: 2734

Before trying my suggestions please check the answer from Sanja Paskova.

I can see a few potential problems here:

1) You are using By.css() with an uppercase B instead of by.css() with lowercase b. I don't know if it's the same.

2) element.all() returns an ElementArrayFinder and not an ElementFinder. You should either use element.all(by.css('foo')).first().sendKeys('bla'); OR element(by.css('foo')).sendKeys('bla');.

3) If it's not point 1 and 2 try to click the input before sending keys:

  var input = element(by.css('.form-control.validation-field.ng-dirty.ng-valid.ng-touched'));
  input.click().then(function() {
      input.sendKeys('sample code');
    });

Just some guesses.

Upvotes: 0

Bharath Kumar S
Bharath Kumar S

Reputation: 1408

Using class name is not encouraged because they may change in near future.

Suppose you are trying to input user name the preceding node will contain visible text (i.e) user name or something

Try to find that node and then following input element.

example:

//*[contains(text(),"User Name")]/following-sibling::input

Upvotes: 0

Sanja Paskova
Sanja Paskova

Reputation: 1110

It looks like your css is not correct, instead of .ng-valid you should place .ng-invalid

element.all(By.css('.form-control.validation-field.ng-dirty.ng-invalid.ng-touched')).sendKeys('sample code');

Upvotes: 3

Related Questions