Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get All Elements of Certain Type on a Website

Tags:

sapui5

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

like image 954
Konstantin Dobler Avatar asked Jan 21 '26 23:01

Konstantin Dobler


2 Answers

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.

like image 101
Boghyon Hoffmann Avatar answered Jan 26 '26 17:01

Boghyon Hoffmann


I found this solution:

I get all elements of the class sap.m.Input from the DOM-Tree with document.getElementsByClassName("sap.m.Input")`.

I then get the corresponding UI5-Elements by calling sap.ui.getCore().byId() on the ID of each element of that array.

like image 22
Konstantin Dobler Avatar answered Jan 26 '26 17:01

Konstantin Dobler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!