enthought / enthought/traitsui
UITester.find_by_id only works for element that has enabled_when
- Dominant language
- Python
- Stars
- 306
- Forks
- 99
- PR merge metrics
- No merged PRs in 30d
Description
It seems that if an element does not have "enabled_when" or "visible_when" you cannot use "find_by_id" in the from the ``UITester``. I wonder if it is by design. You might think that you do not need to search them if they always enabled or visible. If it is the case, then I think the documentation or at least the docstring should be improved.
Here is a small demo for the issue. When you run it you get "AttributeError: 'UIInfo' object has no attribute 'identification'". If you un-comment one line identified in the code, then it works.
```
from traits.api import HasStrictTraits, Instance, Str
from traitsui.api import HGroup, ModelView, UItem, VGroup, View
from traitsui.testing.api import UITester
class Employee(HasStrictTraits):
name = Str()
position = Str()
class EmployeeView(ModelView):
model = Instance(Employee)
def default_traits_view(self):
return View(
VGroup(
HGroup(
UItem("model.name"),
id="identification",
# un-comment the following line to see the link with enabled
# enabled_when="model is not None",
),
HGroup(UItem("model.position")),
)
)
def demo():
employee = Employee(name="Steve", position="ssd")
view = EmployeeView(model=employee)
tester = UITester()
with tester.create_ui(view) as ui:
tester.find_by_id(ui, "identification")
if __name__ == '__main__':
demo()
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.