Calculate Size / Location of Element from Page Source

I want to calculate Size / Location of Elements in Appium Page Source.
i.e.

<android.widget.Button index="1" text="" class="android.widget.Button" package="com.samsung.shtvs.sbs.mobilerms" content-desc="Set Server IP" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[252,600][416,634]" resource-id="" instance="1"/>

I know bounds attribute contain size / location. but , which one is size [252,600] , location [416,634] ??
or vice versa ??

My requirement is i wrote some wrapper for page source. i want to convert this page in pure html page.
i.e. Button = <input type = 'button' style='top:'?px'; left:'?px'; width:'?px'; height:'?px';' text = 'Set Server IP' />

I tried with both size [252,600] , location [416,634] and location [252,600] , size[416,634] .

But , din`t get proper rendering.

Thanks in advance.

Those are the bounds, upper left and lower right corners of the object. The size is [(416-252), (634-600)]

Thanks Mr. Willosser for quick supports.

Size will be in px right ?
<input type = 'button' style='top:'?px'; left:'?px'; width:'164px'; height:'34px';' text = 'Set Server IP' />

What will be exact position in bounds ??

@arundutt83, yes, in pixels.

I’m having trouble understanding your second question. Can you elaborate or restate?

Mr. Will,

what will be the location of element from the given bounds.

I want to render below source code in html file

<android.widget.Button index="1" text="" class="android.widget.Button" package="com.samsung.shtvs.sbs.mobilerms" content-desc="Set Server IP" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[252,600][416,634]" resource-id="" instance="1"/>

since, bounds contains location also.hence, what will be the location (i.e. top , left). so, i can render these element in html.
that will be look like same ui as rendered in android screen.

The first numerical pair in the bounds is the upper left hand corner, 252,600

Thank You Sir,
I got your point. Yes, Now, UI is rendering as per expectation but still need improvement.
I have one more concern.
If i get page source by driver.getPageSource() then this command will display all ui source in xml.
but, how to know this element is visible on screen or not ?

  • Suppose one screen contain 2 buttons ( A / B). If A press some elements display & when B press A elements hide and B`s element display.

I want to get only A Elements when it is active or for B vice versa.

At that point, you use the other tools in appium to detect if the element is present. You can find the element by name (text or content-desc) or resource-id (if present). Alternatively, you can parse the page source that you already have there. We can see that you have a relatively unique content-desc, so find the element by name matching ‘Set Server IP’.

Thanks Mr. Willosser,
Yeah, we can find elements by name or resource-id.
Suppose, two buttons are given in xml source code(resource-id, content-desc/text are given null).
but, only one is displayed on android screen(i.e. activity) then how to know second one is hidden.
is there any properties in appium to get this information. ?

When you test on Android, you know nothing about what isn’t on the screen.

There is an api in the appium driver for find_elements() which returns an array. If you know two should be visible, but the length of the element list is one, then you can infer the other one is off screen.

Ok, I`ll check this.
Can you please give your valuable suggestion on below issue ?

@arundutt83, I’m sorry, but I’ve never needed to capture user events. I have no useful suggestions on that front for you.

Anyways Thank You Mr. Will Osser
You tried a lots for me to find the quick solution.
I can see you are the active user for many members.
Whenever i`ll have problem , i contact you.

@willosser ca you please tell me how to get the screen size scaling ratio? I have a JavaFX webview. I need to render screen shot image inside webview. I have a fixed width and height to webview. please tell me how to render the full image inside it ?

Thank you