GetValue from GUI element

Class library usage, coding and language questions.
deatchlock
Posts: 27
Joined: Mon Mar 19, 2018 10:02 am

GetValue from GUI element

Post by deatchlock » Mon Mar 19, 2018 10:09 am

Hi,

i am interested how to GetValue from certain GUI element and store it to the list during the run time? The goa of my Test is to go through the all GUI elements and to GetValues in my case ( captions or text ) and after storing these values to translate them to a choosen language.

Any help would be appreciated. :)

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

Re: GetValue from GUI element

Post by odklizec » Tue Mar 20, 2018 8:28 am

Hi,

Unfortunately, there is not enough info to provide a reasonable answer. Usage of GetValue action is pretty simple, but without seeing your app (at very least Ranorex snapshot) and some exact steps what you want to do, it's pretty hard to suggest something meaningful.

A general suggestion could be to use GetValue where you want and store obtained values to file (e.g. CSV). Of course, you will have to use coding for this part. A lot of examples how to store data to file can be found either by searching this forum or by googling some C# samples.
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

deatchlock
Posts: 27
Joined: Mon Mar 19, 2018 10:02 am

Re: GetValue from GUI element

Post by deatchlock » Tue Mar 20, 2018 9:05 am

Hi odklizec,

thank you for the reply. Unfortunately I don´t have anything yet to provide you with but I can give you descrpition of what I itend to do:
Steps:
1) Start MAX - (our Windows application)
2) Get the captions (values) from GUI during the runtime
3) Determine the language of the application using the majority of the original words
4) Translate the captions using the translator ( Google translator for example) and store them.
For example format of stored value could look like [History / EN] or [Verlauf / DE]
5) Check the translation here we would have three possible outcomes:

Correct if --> Translation and Original value both are correct
Correct if --> Translation and Language are both correct
Wrong if --> Translation is not correct or wrong language selected

But at the moment I don´t understand how to use GetValue method in code, how to store a value in to the List or as you said to the CSV. It is not a bit issue to get c# implementation store something but this part of catching the value is what I can´t get correctly.

For example in this particular case I loop through the GUI elemnts and during this process I would like to store values ( captions ) of the buttons to the list. I am aware of adding GetValue method in the recording but how to use it in this particular case?

IList<Ranorex.Button> tbContainers = Host.Local.Find <Ranorex.Button>("/form[@title='KePlus MAX']/container/container[2]/list[1]/button");

foreach(Ranorex.Button tbContainer in tbContainers)
{
tbContainer.MoveTo();
Ranorex.Report.Screenshot (tbContainer);
Ranorex.Report.Info("Looping through the buttons");
Ranorex.Delay.Milliseconds(200);
}

Thank you for responding back. :)

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

Re: GetValue from GUI element

Post by odklizec » Tue Mar 20, 2018 9:44 am

Hi,

I would suggest to use repo element instead of xpath, which is hard to maintain from code. Simply pass the repo element to method like this:

Code: Select all

		public void UserCodeMethod(RepoItemInfo buttonRepoItem)
		{
			IList<Ranorex.Button> buttonList = buttonRepoItem.CreateAdapters<Ranorex.Button>();
			foreach(Ranorex.Button button in buttonList)
			{
				string captionString = button.Element.GetAttributeValueText("Caption");
				Ranorex.Report.Screenshot(button); 
				Ranorex.Report.Info(captionString);
				Ranorex.Delay.Milliseconds(200);
			}
		}
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

deatchlock
Posts: 27
Joined: Mon Mar 19, 2018 10:02 am

Re: GetValue from GUI element

Post by deatchlock » Tue Mar 20, 2018 9:58 am

Thank you for the advice and help.

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

Re: GetValue from GUI element

Post by odklizec » Tue Mar 20, 2018 10:06 am

You are welcome! ;)
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

deatchlock
Posts: 27
Joined: Mon Mar 19, 2018 10:02 am

Re: GetValue from GUI element

Post by deatchlock » Wed Mar 21, 2018 10:15 am

Hi odklizec,

I have tried to implement your proposal but I cannot get how to give a path to the "buttonRepoItem". Since I have to provide something there.
I have tried this buttonRepoItem = Host.Local.Find <Ranorex.Button>("/form[@title='KePlus MAX']/container/container[2]/list[1]/button");
and then to pass it to the method which you have written. The mentioned proposal is always giving me the syntax error. I apologize for bothering you but I am new to the Ranorex and to the syntax of Ranorex.

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

Re: GetValue from GUI element

Post by odklizec » Wed Mar 21, 2018 10:32 am

    Hi,

    You need to pass the element as a method argument. There is no way to obtain the info element from code.

    Simply create a new user code action in repo, ideally, by dragging and dropping the button element from repository to recording module of your choice. You should be provided with context menu, where you can select User Code, then "new method with argument Repo Item Info"...
    UserCode_with_RepoItemInfo.png
    UserCode_with_RepoItemInfo.png (23.91 KiB) Viewed 464 times
    Then simply replace the content of method with the one I posted above. Hope this helps?

    BTW, the repo element should return list of buttons! So don't forget to make its xpath that way!
    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

    deatchlock
    Posts: 27
    Joined: Mon Mar 19, 2018 10:02 am

    Re: GetValue from GUI element

    Post by deatchlock » Wed Mar 21, 2018 12:50 pm

    Hi,

    thank you. Now I now how you did it in a way to modify a certain element from repo in the code. I have changed my xpath from ...container/container[2]/list[1] --> this is defined in the code by default and this list conatins buttons, to
    ...container/container[2]/list[1]/button --> this way I am able to access the buttons in the list so I can acctually iterate through it. Frankly I don´t understand why it is so maybe because I have defined in the code IList<Ranorex.Button> and it is looking for the buttons and can´t recognize list.

    But going back to the point I don´t really get what do you mean by return the list (is it the xpath that I mentioned in parahraph above) since I have void method and cannot return anything there. Also I don´t get any results back from the runing the test case althouh it is "green", positive outcome. At least I should see something since I ahve "Ranorex.Report.Info(captionString);" which should prompt at least one "Caption" which is stored. And I have added "var stringList = new List<string>();" so I can store captions in to the list during the looping process.

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

    Re: GetValue from GUI element

    Post by odklizec » Wed Mar 21, 2018 1:08 pm

    Hi,

    Things would be much easier if you post a Ranorex snapshot of the application under test (AUT). With snapshot, I can easily show you the xpath you need to use.

    By returning list of buttons, I don't mean that the method should return list of elements. I just mean that the xpath should be generic enough to provide "list" of buttons, which can be looped and from which you can get caption for each single button. I guess the xpath you posted (container/container[2]/list[1]/button) is exactly what you want? However, it will return a list of buttons from container[2]/list[1]. If there are more containers and lists in the AUT, you need to eliminate the indexes behind the "container" and "list" elements to get buttons from all containers and lists. BTW, using indexes in the xpath is not a very good idea and should be avoided (if possible). Ranorex recorder adds them by default, if there are no other (usable) identification attributes found. But it's your task to eliminate them, eventually replace them with something more reasonable (e.g. relationship operators).
    Attachments
    ListOfButtons.png
    ListOfButtons.png (86.5 KiB) Viewed 458 times
    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

    deatchlock
    Posts: 27
    Joined: Mon Mar 19, 2018 10:02 am

    Re: GetValue from GUI element

    Post by deatchlock » Wed Mar 21, 2018 3:19 pm

    Hi,

    seems that is the possible path, but please find attached my snapshot so you can have look. But please remove it after you take a look at it, thank you :)
    One more point it seems that it doesn´t take the values from buttons in my case Captions, i just get empy report.

    Regards,
    Attachments
    ButtonsList.rxsnp
    (160.72 KiB) Downloaded 10 times

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

    Re: GetValue from GUI element

    Post by odklizec » Wed Mar 21, 2018 3:30 pm

    Hi,

    The reason why you are getting empty text from Caption is that there is no Caption attribute for given buttons ;) You need to use "Text" attribute instead.

    As for the xpath, as I thought, there are multiple buttons in your GUI, so using element indexes is most probably not a very good idea. You just have to change the xpath based of the level of search (for buttons) you want to implement...
    button_list.png
    button_list.png (96.23 KiB) Viewed 454 times
    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

    deatchlock
    Posts: 27
    Joined: Mon Mar 19, 2018 10:02 am

    Re: GetValue from GUI element

    Post by deatchlock » Wed Mar 21, 2018 3:50 pm

    Hi,

    super, thank you very much for your effort and time. :D I have added also a writting to CSV just to check if it will write the output to it. Can I reach to you again in the case I got stuck somwhere in Ranorex?

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

    Re: GetValue from GUI element

    Post by odklizec » Wed Mar 21, 2018 3:53 pm

    You are welcome. Feel free to post here in case you stuck with something else ;)
    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