Unable to check/uncheck checkbox

170 views
Skip to first unread message

Gina Doll

unread,
Aug 26, 2020, 8:27:02 PM8/26/20
to Selenium Users
New to Selenium IDE. Using in Chrome. Need to check/uncheck checkboxes. The Click  command has no effect. The Check command returns the error, " Element css=.sc-exAgwC:nth-child(3) > .sc-gojNiO:nth-child(1) is not a toggle-button." Any ideas?

Thank you,
Gina

Adrian

unread,
Aug 27, 2020, 7:01:09 PM8/27/20
to Selenium Users
Hi,
Could you please post a pic of the DOM for the checkbox.

Regards,
Adrian.

Gina Doll

unread,
Aug 27, 2020, 10:47:42 PM8/27/20
to seleniu...@googlegroups.com
Hi Adrian,

Thanks for your response! What’s the DOM?

Thank you,
Gina

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/da8b28ce-d333-47f1-9d6f-09468f877543n%40googlegroups.com.

ddlionx

unread,
Aug 28, 2020, 2:26:41 AM8/28/20
to seleniu...@googlegroups.com

Gina Doll

unread,
Aug 28, 2020, 2:44:42 PM8/28/20
to seleniu...@googlegroups.com

Gina Doll

unread,
Aug 28, 2020, 7:08:46 PM8/28/20
to Selenium Users
I think that this is the DOM. It's one of the pages where I'm trying to check checkboxes with Selenium IDE. Thanks!
Zammo checkboxes DOM.PNG

Adrian

unread,
Aug 30, 2020, 5:24:47 PM8/30/20
to Selenium Users
That is a picture of the UI.
To get the DOM you need access to the Dev Tools.  
Right click on the page and select Inspect from the popup menu - this will display the Dev Tools.  The DOM is displayed in the Elements tab.
Then right click on the checkbox and select Inspect again.  This will display the checkbox in the DOM,  It might look something like this:

<td class="text-primary"><input style="margin-top: 10px;" class="pull-left ng-pristine ng-valid ng-empty ng-touched" ng-model="data.currentSortedDocuments['/4194D1706ED1F408D5E02D672777019F4D5385C766A8C6CA8ACBA3167D36A7B9']['/4194D1706ED1F408D5E02D672777019F4D5385C766A8C6CA8ACBA3167D36A7B9/360398-Friday-Dance-Time (1) (1) (1).jpg'].selected" type="checkbox" ng-click="drawDatatableFolders()"> <button ng-show="level >= 0 &amp;&amp; countSelectDeselectRow('/4194D1706ED1F408D5E02D672777019F4D5385C766A8C6CA8ACBA3167D36A7B9') <= 0" ng-click="customSeeNotes('/4194D1706ED1F408D5E02D672777019F4D5385C766A8C6CA8ACBA3167D36A7B9/360398-Friday-Dance-Time (1) (1) (1).jpg')" tooltip="" title="Show Versions" class="btn btn-default btn-outline btn-sm pull-right text-muted version-number" style="margin-top: 8px"> V1</button></td>

Gina Doll

unread,
Aug 31, 2020, 8:02:20 PM8/31/20
to seleniu...@googlegroups.com
Cool! I didn't know all of that information was in there! The line selected in the DOM relates to Inspecting the first checkbox in the app:

image.png

Adrian

unread,
Sep 1, 2020, 5:48:26 PM9/1/20
to Selenium Users
Excellent!
There is a lot happening here.  I can see your checkboxes are part of a table and there are IDs that you can work with.
The easiest way to try and access the checkbox by its ID.
I can see that the ID of the checkbox that is checked is called question-0.  I'm guessing that the next checkbox is called question-1 and so on.
Therefore you can locate and check the checkbox based on it ID with driver.findElement(By.Id("question-0")).click();

Now this is where it get tricky.  Looking at the DOM, I can't tell if that checkbox is checked or not.  So clicking on the element might be unchecking the checkbox.  I would recommend asking the Developers how you can tell from the DOM if the checkbox is checked or not.  They might have to add extra information in the DOM for you to know this.

If searching for the checkbox by ID doesn't work there are other ways.
You can find all the inputs with the type checkbox and then iterate through the results for the required ID or text that matches the checkbox label.

C#
var allCheckboxes = driver.findElements(By.cssSelector("input[type='checkbox']"))
foreach (checkbox in allCheckboxes)
{
    if (checkbox.id == "question-0")
      checkbox.Click()
}

Or you could try:
var allCheckboxes = driver.findElements(By.cssSelector("input[type='checkbox']"))
foreach (checkbox in allCheckboxes)
{
    if (checkbox.Text == "How do I contact you?")
      checkbox.Click()
}

Or there are potentially other ways to get this info via the class name.


Goodluck,
Adrian.

Gina Doll

unread,
Sep 1, 2020, 5:54:45 PM9/1/20
to seleniu...@googlegroups.com
Thank you Adrian! I will give it a try, but where? In Selenium IDE do I write "run" in the Command field followed by your code in the Target field?

Thanks,
Gina

Adrian

unread,
Sep 2, 2020, 5:11:55 PM9/2/20
to Selenium Users
Sorry, I haven't used Selenium IDE.

Gina Doll

unread,
Sep 3, 2020, 1:37:06 PM9/3/20
to seleniu...@googlegroups.com
Hi Adrian,

Selenium IDE uses JavaScript. I used the Command "check" with the Target "id=question-0" and it worked!!! Thanks for your help!

Gina

On Tue, Sep 1, 2020 at 2:49 PM Adrian <lord.s...@gmail.com> wrote:

Adrian

unread,
Sep 3, 2020, 5:43:43 PM9/3/20
to Selenium Users
That's great news!
Well done.

Cheers,
Adrian.

Kai Abraliev

unread,
Sep 4, 2020, 2:11:22 AM9/4/20
to seleniu...@googlegroups.com
Hey Gina
For checkbox or radiobutton validation you can use - assert checked OR assert not checked for Command field
and use id for Target field - id for each element (checkbox or radiobutton)  - ( use Inspect element to find id )
See screenshot below
image.png

-Kai

Gina Doll

unread,
Sep 4, 2020, 7:10:34 PM9/4/20
to seleniu...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages