How to Get Value of item and run steps based on value

Best practices, code snippets for common functionality, examples, and guidelines.
armstronghm24
Posts: 42
Joined: Tue Dec 20, 2016 10:16 pm

How to Get Value of item and run steps based on value

Post by armstronghm24 » Fri Nov 17, 2017 9:23 pm

Hi,

I am trying to run a few test steps based on the text within an error message. I am unable to get my user code to work. I tried this:

Code: Select all

        public void MergedUserCodeMethod1(RepoItemInfo textInfo, RepoItemInfo buttonInfo, RepoItemInfo checkboxInfo, RepoItemInfo radiobuttonInfo)
        {   
        	
        	Report.Log(ReportLevel.Info, "Get Value", "Getting attribute 'Text' from item 'textInfo' and assigning its value to variable 'VarDateAgeError'.", textInfo);
            VarDateAgeError = textInfo.FindAdapter<Text>().Element.GetAttributeValueText("Text");
            
            
            if (VarDateAgeError.Equals("Interest Rate Must be Selected for This Plan."))
                {
            		Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click item 'buttonInfo' at Center.", buttonInfo);
           		    buttonInfo.FindAdapter<Button>().Click();
                    Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click item 'checkboxInfo' at Center.", checkboxInfo);
                    checkboxInfo.FindAdapter<CheckBox>().Click();
                    Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click item 'radiobuttonInfo' at Center.", radiobuttonInfo);
                    radiobuttonInfo.FindAdapter<RadioButton>().Click();
                }
        }
It didn't work.

Anyone have any ideas?

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

Re: How to Get Value of item and run steps based on value

Post by odklizec » Mon Nov 20, 2017 8:45 am

Hi,

Could you please be a bit more specific, what exactly is not working? Is there an error message you are getting? Or the GetAttributeValueText does not extract the text from the provided element?

Also, please post a Ranorex snapshot of the problematic error message and ideally, also a sample app, in which we can test the code you provided. The Ranorex solution would be helpful too.

BTW, are you sure the error message is shown at a time your code is running? The code looks fine, but without knowing more details, there is not much anyone here can do or suggest. In my opinion, you should examine the popupwatcher sample code:
https://www.ranorex.com/help/latest/cod ... tedDialogs
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