javascript - Protractor - How to get actual values from the Repeater, not the Elements? -


i creating protractor script test quiz game puts random questions , answers, need script able figure out answer correct, can click it.

i can't figure out how values directly model, instead of elements, since correct/incorrect not exposed element on page.

the model provides answers in choice in question.choices, , need find choice choice.iscorrect true. how access value?

i wouldn't use element() function, right?

element(by.repeater('choice in question.choices').row(0).column('choice.iscorrect')) 

the idea use element.all() in conjunction filter() , evaluate():

var correctchoices = element.all(by.repeater('choice in question.choices')).filter(function (elm) {     return elm.evaluate('choice.iscorrect').then(function (value) {         return value;     }); }); 

as result correctchoices contain elements choice.iscorrect truthy.


if need array of values correct choices, use map() , getattribute():

correctchoices.map(function (elm) {     return elm.getattribute('value'); }); 

or, if need texts make use of gettext():

correctchoices.map(function (elm) {     return elm.gettext(); }); 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -