How to use if condition in ranorex

Ask general questions here.
ejji09
Posts: 54
Joined: Thu Sep 10, 2015 2:48 pm

How to use if condition in ranorex

Post by ejji09 » Thu Oct 22, 2015 9:40 am

Hi,

Am using code module and am tracking the atributes and writing the code, here i got a problem
after logging into my application a dailouge will apperas some time so for this i want to write if condition and i dont know how to give condition in ranorex. I tried like this but it doesnt work for me

Code: Select all

var notForPatientUse = repo.NotForPatientUse;
  var buttonOK = repo.NotForPatientUse.ButtonOK;
if (notForPatientUse)
{
buttonOk.Click();
}

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

Re: How to use if condition in ranorex

Post by odklizec » Thu Oct 22, 2015 10:09 am

Hi,

Try to replace this line:

Code: Select all

var notForPatientUse = repo.NotForPatientUse;
with this:

Code: Select all

var notForPatientUse = repo.NotForPatientUseInfo.Exists();
or simply use it in condition like this

Code: Select all

if (repo.NotForPatientUseInfo.Exists())
{
}
Where the "Info" object is a special object available for each repo element, which you can use to read various repo element attributes without accessing UI (to prevent exception). For more details about Info object, check this User Guide paragraph...
http://www.ranorex.com/support/user-gui ... html#c3197
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

ejji09
Posts: 54
Joined: Thu Sep 10, 2015 2:48 pm

Re: How to use if condition in ranorex

Post by ejji09 » Thu Oct 22, 2015 10:49 am

I tried as you said but am getting errors

Code: Select all

var notForPatientUse = repo.NotForPatientUseInfo.Exists();
            var buttonOK = repo.NotForPatientUse.ButtonOK;

            if (NotForPatientUseInfo.Exists())
             {
             	buttonOK.Click();
             } 

1st error
'TestRIS_i.TestRIS_iRepository' does not contain a definition for 'NotForPatientUseInfo' and no extension method 'NotForPatientUseInfo' accepting a first argument of type 'TestRIS_i.TestRIS_iRepository' could be found (are you missing a using directive or an assembly reference?) (CS1061) - C:\Users\212453330\Documents\Ranorex\RanorexStudio Projects\TestRIS-i\TestRIS-i\LOGIN.cs:60,41
2nd error:
The name 'notForPatientUseInfo' does not exist in the current context (CS0103) - C:\Users\212453330\Documents\Ranorex\RanorexStudio Projects\TestRIS-i\TestRIS-i\LOGIN.cs:63,17

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

Re: How to use if condition in ranorex

Post by odklizec » Thu Oct 22, 2015 11:21 am

Hi,

It would be much easier to help you if you post a Ranorex snasphot (not screenshot) of the problematic repo element (NotForPatientUse). Please post also a screenshot of your repository, where we can see the structure of your repository (particularly location of NotForPatientUse element in repo tree). Thanks.
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

ejji09
Posts: 54
Joined: Thu Sep 10, 2015 2:48 pm

Re: How to use if condition in ranorex

Post by ejji09 » Thu Oct 22, 2015 1:25 pm

Please find the Ranorex snapshot
https://app.box.com/s/2uwl8q58wa4akjr9s8p3mhpdwdkdbsru

Please find the attchment of the Dailogue screenshot
https://app.box.com/s/1mw2mltmnf60zr8k5jh4dfxv4n3dot9e

Please find the link to download screenshot of repository
https://app.box.com/s/jbif8oz48kveu2qv61aunw6jkg29m1lc

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

Re: How to use if condition in ranorex

Post by odklizec » Thu Oct 22, 2015 1:50 pm

Hi,

OK, it seems there is no info object generated for some Java-based elements? Anyway, you should be able to use SelfInfo instead:

Code: Select all

var notForPatientUse = repo.NotForPatientUse.SelfInfo.Exists();
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

ejji09
Posts: 54
Joined: Thu Sep 10, 2015 2:48 pm

Re: How to use if condition in ranorex

Post by ejji09 » Thu Oct 22, 2015 2:03 pm

I used like this

Code: Select all

var notForPatientUse = repo.NotForPatientUse.SelfInfo.Exists;
            var buttonOK = repo.NotForPatientUse.ButtonOK;
            if(repo.NotForPatientUse.SelfInfo.Exists())
            {
            
            buttonOK.Click();
            }
and am getting the error as:
Cannot assign method group to an implicitly-typed local variable (CS0815)

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

Re: How to use if condition in ranorex

Post by odklizec » Thu Oct 22, 2015 2:13 pm

There are missing brackets in your code:

Code: Select all

var notForPatientUse = repo.NotForPatientUse.SelfInfo.Exists();
So the entire code should look like this:

Code: Select all

var notForPatientUse = repo.NotForPatientUse.SelfInfo.Exists();
            var buttonOK = repo.NotForPatientUse.ButtonOK;
            if(notForPatientUse)
            {
                buttonOK.Click();
            }
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

ejji09
Posts: 54
Joined: Thu Sep 10, 2015 2:48 pm

Re: How to use if condition in ranorex

Post by ejji09 » Thu Oct 22, 2015 2:22 pm

Thanks man! :D

really its a silly mistake done by me. :roll:

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

Re: How to use if condition in ranorex

Post by odklizec » Thu Oct 22, 2015 2:29 pm

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