How to write browser tests for check boxes?

Hi I am writing browser tests and I need to unselect a checkbox and perform the further actions. So to unselect an a checkbox I write the following code

browser.getForm('form').getControl('form.widgets.mailer:list').value = [u'selected']

I got the form name and checkbox name from inspecting those elements but still when I run the browser tests I am getiing the follwing error

Failed example: browser.getForm('form').getControl('form.widgets.mailer:list').value = [u'selected'] Exception raised: Traceback (most recent call last): File "/usr/lib/python2.7/", line 1315, in __run compileflags, 1) in test.globs File "<doctest browser.txt[38]>", line 1, in <module> browser.getForm('form').getControl('form.widgets.mailer:list').value = [u'selected'] File "/home/prakhar/projects/gsoc16/collective.easyform/eggs/zope.testbrowser-3.11.1-py2.7.egg/zope/testbrowser/", line 403, in getForm form = disambiguate(matching_forms, '', index) File "/home/prakhar/projects/gsoc16/collective.easyform/eggs/zope.testbrowser-3.11.1-py2.7.egg/zope/testbrowser/", line 48, in disambiguate raise LookupError(msg) LookupError

Basically I need to uncheck that box and I am getting error in that. I will like to know how to track the checkbox to uncheck it in browser tests. I am getting error at that point.


The best way to debug it is to use pdb:
import pdb; pdb.set_trace()

And then you can see what's your current page content (browser.contents) and test your controls.

This is a surprising way to "unselect a checkbox". Whether a checkbox is selected or not is usually controlled by the "checked" attribute not by its "value" attribute.

In addition, I see from the name "form.widgets.mailer:list" and its ":list" suffix that you likely have not a single checkbox but a collection of those. The "LookupError" from "disambiquate" likely comes from the fact, that the form does not contain a single "form.widgets.mailer:list" but more of them, and therefore the framework does not know for which of them you want to change the "value".
Likely, you expect too much from the testing framework: A human expect can see from the ":list" suffix that the html represents something with a list value; however, the testing framework likely works only an the html level and does not interprete the control names. This would mean that you cannot assign list values but must work on individual controls at the html level.

don't use browser tests; use RobotFramework: