mardi 28 novembre 2017

Protractor - select checkbox if not selected

I try execute in protractor following scenario:
1. Find checkbox
2. Check if it is selected
- If yes - go further
- If not - select it and go further

For some reason isSelected() function is not working with my checkbox, but I've found some solution. Below code works correctly:

expect(checkbox.getAttribute('aria-checked')).toEqual('false')

It checks some checkbox attribute which is 'false' if not selected and 'true' if selected. (but as a string)

Now the main question. How to write an 'if / else' statement to make it works?

I tried something like that:

if (expect(checkbox.getAttribute('aria-checked')).toEqual('false')) {
 checkbox.click();
}

But it always clicks on checkbox no mater if it was selected or not. I've tried also:

if (checkbox.getAttribute('aria-checked').toEqual('false')) {
 checkbox.click();
} 

But there is an error which says "It's not a function".

Could anybody help me with that?

Aucun commentaire:

Enregistrer un commentaire