UI Toolkit UQuery not finding element

I created a custom element and am trying to use UQuery to find different ones but have come up against a very strange issue that I don’t understand.

On Start, I can call this and it works:

VisualElement Otpb = v_ActiveGameDisplay.Q<VisualElement>("Openness-tpb");
TreatmentTraitProgressBar O = Otpb.Q<TreatmentTraitProgressBar>();
Debug.Log(O.value);

But, the following does not work. It finds the Label but not the custom TreatmentTraitProgressBar, which just seems odd.

v_ActiveGameDisplay.Query<VisualElement>().ForEach((element) => {
    if (element.name.Contains(trait.name.ToString()))
    {
        TreatmentTraitProgressBar ttpb = element.Q<TreatmentTraitProgressBar>();
        Label l = element.Q<Label>();
    }
});

Any help would be greatly appreciated, thank you!

This is not a good query as enumerating every VisualElement is not a good idea while also being unnecessary as well.

Try filtering by name where possible:

v_ActiveGameDisplay
    .Query<VisualElement>( trait.name )
    .Children<TreatmentTraitProgressBar>()
    .ForEach( bar => {} );