Identification of "div" element in hybrid app

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
User avatar
FelixK98
Posts: 54
Joined: Fri Apr 08, 2016 6:28 am

Identification of "div" element in hybrid app

Post by FelixK98 » Thu May 19, 2016 5:59 am

Hi Everyone,

I got "div" element with InnerText value only. I got a few of them in our hybrid app.
Ranorex Spy gives the following info:
XPath = /mobileapp[@title='au.com.planetinnovation.gidget']/form/container[@containertype='']//container[@containertype='ViewControllerWrapper']/?/?/container[@containertype='ViewControllerWrapper']//dom[@domain='localhost']//div[#'app']/div/div[3]/div/div/div[1]/div[@innertext='Lesley Brown']
Spy_info_for_div_element.PNG
Spy info
Spy_info_for_div_element.PNG (90.45 KiB) Viewed 982 times
I changed XPath to
XPath=/mobileapp[@title='au.com.planetinnovation.gidget']/form//dom[@caption='Gitget']//div[#'app']/div/div[3]/div/div/div[1]/div[@innertext='Lesley Brown']
Can someone suggest the way to set XPath without @innertext='Lesley Brown'?

It takes more then 9 seconds at run time to find element and I am getting app timeout which can't be more then 10 seconds (it is requirement).
How can I identify "div" element which got only value for InnerText attribute and I can't use it due to dynamic nature of this value?

I can't use class value because it is the same for a few div elements.

Thanks,
Felix.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3908
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Identification of "div" element in hybrid app

Post by odklizec » Thu May 19, 2016 7:21 am

Hi Felix,

Please post a Ranorex snapshot of the element in question. Screenshot is unfortunately not helpful to determine best (or better) xpath.

BTW, looking at the screenshot, it seems to me that your app lacks of unique attributes and so you will have to use either "Class" attributes (change the xpath weight to give the Class attribute a priority over other attributes) or a combination of Class attributes, available IDs and relative references. But again, without snapshot, it's pretty hard (impossible) to suggest something reliable.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

User avatar
FelixK98
Posts: 54
Joined: Fri Apr 08, 2016 6:28 am

Re: Identification of "div" element in hybrid app

Post by FelixK98 » Thu May 19, 2016 7:57 am

Hi odklizec,

Here is a snapshot for the div element:
div-element.rxsnp
Snapshot
(56.61 KiB) Downloaded 45 times
Thanks,
Felix.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3908
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Identification of "div" element in hybrid app

Post by odklizec » Thu May 19, 2016 8:20 am

I'm sorry, but there is no div element (Lesley Brown) as shown in your screenshot. The last div available shows something like "Please scan a label to begin...". Also, it would be useful, if there would be saved complete structure as shown in screenshot (displayed multiple persons in GUI).

BTW, why have you removed most of the containers from the xpath? The reason of long search time is, that the modified xpath contains very few IDs and your simplified xpath contains no ref. elements between 'form' and 'dom' element, which means Ranorex needs to search entire GUI (starting from 'form') for the presence of 'dom' element. And this can take a long time, considering the complicated structure of GUI.

Also, the caption of 'dom' element (saved in snapshot) is 'Gidget' and not 'Gitget' as in your xpath!

Finally, what exactly you want to achieve? Select first person in GUI or select particular person?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

User avatar
FelixK98
Posts: 54
Joined: Fri Apr 08, 2016 6:28 am

Re: Identification of "div" element in hybrid app

Post by FelixK98 » Thu May 19, 2016 8:45 am

Hi,

I am sorry, I didn't check the snapshot.
Here is the updated one:
div-element.rxsnp
Snapshot
(77.47 KiB) Downloaded 40 times
The XPath I am using in repository for first person is:
/mobileapp[@title='au.com.planetinnovation.gidget']/form//dom[@caption='Gidget']//div[#'app']/div/div[3]/div/div/div[1]/div[1]
I have to validate that person's name and ID are correct pair for given name and ID which I have on Server.
So before validation I am getting data from server as a hash table and only then I validate in app during scan stimulation.
Hash table contains all personalities relevant to scan session I am going to perform. So I have to be able validate name and ID for any person.

Thanks,
Felix.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3908
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Identification of "div" element in hybrid app

Post by odklizec » Thu May 19, 2016 9:33 am

Hi,

OK, here is the xpath, that should speed the search time:
/mobileapp[@title='au.com.planetinnovation.gidget']/form//container[@platformclass='MMDrawerCenterContainerView']/container[@containertype='LayoutContainer']//container[@containertype='ViewControllerWrapper']/container[@platformclass='UIView']//container[@platformclass='UIView']//dom[@caption='Gidget']//div[#'app']/div/div[@class='mdl-layout__container']/div[@class~'mdl-layout mdl-js-layout']/div[@class='mdl-layout__content']/div[@class~'mdl-card pi-witness-session-recipient-card']/div[@class~'mdl-card__title']
You may try to reduce the xpath a bit by removing some of the elements, but you need to test the impact of removed elements on search speed.

If you want to instruct Ranorex to contstruct xpath (during recording) based of the class, platformclass and containertype attributes, you need to change the xpath weight to give these attributes a priority over other attributes. Typically, class names have very low priority/weight value, because they are not unique enough. But because there are no other usable attributes in your GUI, it's better to use these attributes over element indexes (like div[1]).

You can find a detailed description how to set path weight in this article:
http://www.ranorex.com/blog/automated-t ... namic-ids/

As for the person validation, I'm not quite sure I understand your actual validation process/requirement? And sadly, the snapshot you posted does not contain other persons than just 'Lesley Brown' so it's hard for me to suggest a code to validate each person.

Basically, I would suggest to create a list of elements containing the individual names and validate this list against the reference list. To create a list of elements with names, you can use something like this:
http://www.ranorex.com/support/user-gui ... html#c3574
However, you may need to make the repo xpath more generic, to return all elements with names. But as mentioned, it's hard for me to create such generic xpath from the actual snapshot, because there is just one person displayed. Please post the snapshot showing the state of GUI as displayed in your initial screenshot.
Last edited by odklizec on Fri May 20, 2016 12:34 pm, edited 1 time in total.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

User avatar
FelixK98
Posts: 54
Joined: Fri Apr 08, 2016 6:28 am

Re: Identification of "div" element in hybrid app

Post by FelixK98 » Fri May 20, 2016 5:54 am

Hi odklizec,

Thank you for your help. I made changes as per your suggestion and got desired result.
All tests are running well.

As per persons info in app I can show you the following snapshot:
snapshot3.rxsnp
(74.51 KiB) Downloaded 43 times
I have to check only first and second person for name and ID.

Thanks,
Felix.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3908
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Identification of "div" element in hybrid app

Post by odklizec » Fri May 20, 2016 12:51 pm

Hi,

Nice to hear it worked ;)

About validating only two names, well this xpath should return all available divs with names:
/mobileapp[@title='au.com.planetinnovation.gidget']/form//container[@platformclass='MMDrawerCenterContainerView']/container[@containertype='LayoutContainer']//container[@containertype='ViewControllerWrapper']/container[@platformclass='UIView']//container[@platformclass='UIView']//dom[@caption='Gidget']//div[#'app']/div/div[@class='mdl-layout__container']/div[@class~'mdl-layout mdl-js-layout']/div[@class='mdl-layout__content']/?/div[@class~'mdl-card pi-witness']/div[@class~'mdl-card__title'or @class~'mdl-card__supporting' and (@innertext!='' and @innertext!~'Dish') ]
So all you need to do is to create a list of 'divs' (via code I've suggested above) and then validate names via loop, limited to just two iterations ;) Hope this helps?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration