In this case, I have a button named btn_pop_up_array.
It is defined within the parent class of class BtnPopupArray (this parent is BtnPopupArrayTemplate below).
Within instances of that class, class member functions refer to it exactly as shown, i.e., self.btn_pop_up_array, e.g.,
class BtnPopupArray(BtnPopupArrayTemplate):
def __init__(self, **properties):
self.btn_pop_up_array.enabled = False
# Set Form properties and Data Bindings.
self.init_components(**properties)
However, as is typical in Python, the name is not part of the object. Each location (namespace) that refers to an object can do so by a different name. The same is true of many other programming languages.
It is an object of Python type (class) anvil.Button. If you print the value of this object it will render as <anvil.Button object>. Python objects that contain data usually print the contained data. But objects that are not just data can print themselves in other ways. The default is <my type name object>.
we found the that each component has a dict which has the “child” components and the ide names, we have used this to set an additional property on each called “ide_name”, we aiming to automate repeatable id’s for selenium based testing so need predictable naming and id’s
I don’t know how you accessed that particular piece of internal component state, but would strongly advise against relying on it, as it can and will change underneath you without warning. Generally speaking, accessing the name of a component isn’t something you should be able to do at runtime. The effect of creating a button called button_1 in the designer should be the same as the Python code:
That is to say, the name itself is not accessible on the Button object; it’s an attribute on the form that points to that object. If you want to identify the button so that others can access information about it, you can attach information to its .tag property (for access from Python), or to its JS DOM object (for access from the browser)
A better way to identify components for testing frameworks is to set attributes or CSS classes on components’ DOM nodes, using the Python<>JS bridge. Here’s a writeup of doing that with Playwright: