Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test placeholder text on input field in Protractor?

We're adding some translations to our applications and I need to make a few protractor tests that grab placeholder text and check that it's being properly loaded.

How do I check the text of the placeholder on an input field using protractor?

like image 228
Justin Avatar asked Oct 22 '14 19:10

Justin


People also ask

How to verify placeholder text in Protractor?

getAttribute('placeholder'). then(function(element){ expect(element). toEqual('<expected placeholder txt>'); }); This works for me.

What is placeholder in textfield?

The placeholder attribute specifies a short hint that describes the expected value of an input field (e.g. a sample value or a short description of the expected format). The short hint is displayed in the input field before the user enters a value.


2 Answers

As mentioned in the Protractor FAQ, try element.getAttribute('value')

like image 81
Brine Avatar answered Nov 12 '22 10:11

Brine


element(by.model('<modelName>')).getAttribute('placeholder').then(function(element){
    expect(element).toEqual('<expected placeholder txt>');
});

This works for me. I used it with model, you can use it with any element you are testing.

like image 23
krishnarajanr Avatar answered Nov 12 '22 11:11

krishnarajanr