1

I am trying to write an end to end protractor test and I am stuck with checking if the checkbox is enabled or not since it does not have the checked property or anything. Is there any way in javascript we could check from a list by getting an element and check if it is checked and if it is checked get the text for that.

This is what i have for the HTML:

<li>

<div _ngcontent-c8="" class="ng-tns-c8-2" >

<input _ngcontent-c8="" class="ng-tns-c8-2" type="checkbox" id="Team TableAccepted">

<label _ngcontent-c8="" class="ng-tns-c8-2" for="Team TableAccepted">Accepted</label></div>

</li>

2 Answers 2

2

isSelected() should do the trick here:

Given this input: <input type="checkbox" id="team" />

To check if it's selected, we would write the following:

const checkbox = element(by.id('team'));

expect(checkbox.isSelected()).toBe(true);

If you do not want to use protractor and would prefer vanilla js, this is another option:

const isChecked = document.getElementById('team').checked;

Also, neither HTML4 nor HTML5 allows space characters in id attribute values. In the case of your input: <input _ngcontent-c8="" class="ng-tns-c8-2" type="checkbox" id="Team TableAccepted">, id="Team TableAccepted is not valid HTML. For id attributes, limit the value to one descriptor.

Hope this helps!

Sign up to request clarification or add additional context in comments.

Comments

0

You can check whether the checkbox is selected/not in two ways

  1. Through the command isSelected()
  2. Through attribute aria-checked=true/false(For mat componenets)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.