Else Block is not executing

Ask general questions here.
mohan.pentyala
Posts: 32
Joined: Thu Sep 20, 2018 7:43 am

Else Block is not executing

Post by mohan.pentyala » Thu Jan 24, 2019 8:58 am

Hi ,

I facing a problem with if else condition When the case is positive IF condition is executing for negative else block is not executing, Application is closing and throwing an exception

if(repo.FusionApp1.btnEDAM.Visible==true)
{
Report. Success ("EDAM button is visible");
repo.FusionApp1.btnEDAM.DoubleClick();

}

else

{
Report.Failure("clicking on NEW button again as it is not clicked first time ");
gl.fn_ClickTopAppBar(con.New);
Delay.Seconds(1);
}

In the above case when the button is visible it should come to else and print the failure.B ut it is not working directly I am getting an exception as not able to identify button.

Can you please help me to resolve this,I know there some small mistake but not able to find it :)

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

Re: Else Block is not executing

Post by odklizec » Thu Jan 24, 2019 9:30 am

Hi,

My guess is, that the element repo.FusionApp1.btnEDAM does not exists (at a time of evaluation) and this is why it fails? Unfortunately, it's hard to tell the exact reason of your problem, without seeing the app under test and your Ranorex project.

What I would do, is to check the existence of RepoItemInfo object and only then evaluate Visible attribute. (Notice the Info at the end of btnEDAM). If you access Info object, there is not thrown an exception in case the element does not exists. The downside of Info object is, that it provides only subset of attributes available in Adapter. So if you want to access attributes available only in Adapter, you must create one from RepoItemInfo object (usign CreateAdapter method)

Code: Select all

if(repo.FusionApp1.btnEDAMInfo.Exists())
{
var repoAdapter = repo.FusionApp1.btnEDAMInfo.CreateAdapter<Ranorex.Unknown>(false);
    if (repoAdapter.Visible==True)
    {
    ...
    }
    else
    {
     ...
     }
Hope this helps?

BTW, you should avoid calling repo elements directly in code! It's much better idea to pass the repo elements to methods via repoiteminfo parameter. Calling repo elements directly in code, makes the code messy and hard to maintain!
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

mohan.pentyala
Posts: 32
Joined: Thu Sep 20, 2018 7:43 am

Re: Else Block is not executing

Post by mohan.pentyala » Fri Jan 25, 2019 8:08 am

Hi

Thank you for the replay but i don't think you understood my question.

Yes, I am calling the repo items from method only.M y problem is ,I wrote the method if eDam button is visible print code insight if the not visible print code under else condition.

So now when eDam button is not displaying it is not printing my else condition code it is directly throwing the exception as not able to find the eDam button with a stack trace.

Ideally, it should print my else condition right?

Anything I can do here, Can you help with this.

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

Re: Else Block is not executing

Post by odklizec » Fri Jan 25, 2019 9:25 am

Hi,

I believe I understand what you are after. But I'm afraid, without seeing, at very least, a Ranorex snapshot (NOT screenshot!) of the problematic element, there is not much else anyone here can do or suggest. Additionally, we need to see the exact error message you are getting (ideally, post the entire rxzlog file).

I still believe that the problem of you code is, that you are directly accessing adapter, instead of repoiteminfo. This is the most probable reason of the failure. Adapter fails, if the accessed repo element does not exists! This is why I suggested to first use Exists method, together with repoiteminfo and only then create an adapter from repoiteminfo and check its visibility status. This is the correct and safest way, how to evaluate element attributes without risking exception, due to not available element (at a time of attribute evaluation).
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

mohan.pentyala
Posts: 32
Joined: Thu Sep 20, 2018 7:43 am

Re: Else Block is not executing

Post by mohan.pentyala » Fri Jan 25, 2019 11:21 am

Thank you ,

Its working and our problem got solved with your approach.

But why we need to create an adapter here, can I create just a variable and assign my repository element and check the visible condition in if?

what is the difference ?

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

Re: Else Block is not executing

Post by odklizec » Fri Jan 25, 2019 12:07 pm

Hi,

The difference between Adapter and RepoItemInfo is in the way Ranorex access them. In case of Adapter, Ranorex tries to search the element and throws an exception in case the element does not exists (within the search timeout). This is what the RepoItmeInfo is for. It can be used in code, without risking "element does not exists" exception. It just does not provide the same amount of attributes and properties, as available with Adapter. And this is why you must create Adapter from RepoItemInfo.
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

mohan.pentyala
Posts: 32
Joined: Thu Sep 20, 2018 7:43 am

Re: Else Block is not executing

Post by mohan.pentyala » Thu Aug 29, 2019 7:58 am

Thanks for your reply.It worked out for me.

Hi,

I got stuck at one more point where I have to create a Ranorex adopter for an image.

Basically the requirement is I have to verify whether the Image is not If visible click on it , else wait for it to visible like drag down the scroll bar to find the element.

Now successfully executing the if block "If visible click on it" but else block is not working out.

Can you suggest any other approach I can try