Search code examples
sapui5

Get All Elements of Certain Type on a Website


I need to find all Input elements (sap.m.Input) on a website. I know I can find an element by its ID via sap.ui.getCore().byId() but this does not help me here.

I am looking for something like sap.ui.getCore().getByType("sap.m.Input"). How do I do this?

Edit: I do not have access to the source code of the website, I am injecting a javascript via a chrome extension on websites which use SAPUI5


Solution

  • From the current page

    <mvc:View ...>
      <Input fieldGroupIds="myInputs" />
    </mvc:View>
    
    // In the Controller
    this.getView().getControlsByFieldGroupId("myInputs").filter(c => c.isA("sap.m.Input"));
    

    From the whole app

    Leveraging this solution in Get list of all instantiated controls in registry:

    const allRegisteredControls = sap.ui.getCore().byFieldGroupId(""); // From https://stackoverflow.com/a/54227512/5846045
    const inputControls = allRegisteredControls.filter(c => c.isA("sap.m.Input"));
    

    API reference: sap.ui.base.Object#isA

    This returns all registered instances of the given type. Please not that already destroyed elements won't be included.