How toContunue after determining not existence of an object

Ask general questions here.
rastek
Posts: 157
Joined: Wed Aug 06, 2014 12:00 pm

How toContunue after determining not existence of an object

Post by rastek » Sun Oct 19, 2014 8:20 am

Hi,

I am trying to determine if a repository item does not exist on the UI. I have a validate step that searches for the item with the condition 'Exists', however my test fails for not finding the path.

I want to click on close button if only if it is there. but test fails..

please help me, my code is below.

if (repo.myApp.Http47168150628580Imag1Info.Exists()) then

else
Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click item 'myApp.Close' at Center.", repo.myApp.CloseInfo, new RecordItemIndex(8))
repo.myApp.Close.Click()
Delay.Milliseconds(200)
End If

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

Re: How toContunue after determining not existence of an object

Post by odklizec » Sun Oct 19, 2014 12:40 pm

Hi ,

Try to use this code...

Code: Select all

if(Validate.Exists(repo.myApp.Http47168150628580Imag1Info,null, false))
Basically, it should validate the element without throwing exception (it sets exceptionOnFail to false). 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

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How toContunue after determining not existence of an object

Post by Support Team » Mon Oct 20, 2014 1:22 pm

The Validate class also logs its results to the report. If you just want to check existence in code, you should stick with the RepoItemInfo.Exists method which you used first.

Regards,
Alex
Ranorex Team
.
Image

rastek
Posts: 157
Joined: Wed Aug 06, 2014 12:00 pm

Re: How toContunue after determining not existence of an object

Post by rastek » Thu Oct 23, 2014 1:49 pm

Hi Odklizac

I tried your solution but get this error

'null' is not declared. 'Null' constant is no longer supported; use 'System.DBNull' instead.

and when I write 'System.DBNull' insted of just 'null' I get this error message

'DBNull' is a type in 'System' and cannot be used as an expression.

What can I do for this error ?

Another thing I get confused that you wrote it sets exceptionOnFail to false

so that will affect my other cases that are real errors needs an exception?

rastek
Posts: 157
Joined: Wed Aug 06, 2014 12:00 pm

Re: How toContunue after determining not existence of an object

Post by rastek » Thu Oct 23, 2014 2:01 pm

Hi

I fixed the code by writing just '0' instead of null and it has ran but it seems it doesnt work properly.

It waits about one minute and says yes even if object is not there ..my code is below

if(Validate.Exists(repo.myApp.dial_pad,0, False))
msgbox("no")
Else
msgbox("yes")
end if

I tried it with another object but it could not find even if object was there..
Shouldnt it find it immedialety when the object is there ??

I do not understand the point is that, why there is no easy way for handling not visible and not exist objects 'n ranorex..

it is interesting that even I insert a Validation Action with Exists from the GUI, ranarex fails for not finding the object in its path.. so what is the logic here ? why Not Exists if it will fail when it can not find the object ??

really confused..

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: How toContunue after determining not existence of an object

Post by krstcs » Thu Oct 23, 2014 2:07 pm

As Alex said, you should probably not use Validate.Exists() and should instead use the RepoItemInfo.Exists() method. This is simpler and still allows you to throw a Validate in the script at some point if you need it.


As for the if statement, you have the two bodies reversed. True result should be in the top section (directly under the IF) and false result should be in the bottom section (after the else), like this:

if(...) {
msgbox("yes")
else
msgbox("no")
end if

I would highly recommend some reading on .NET coding if you do not understand these basic principles.


Also, if your item exists but is not visible, Ranorex will show it as existing even if you can't see it. To get around this, add the @visible='true' attribute check to your RanoreXPath for the object.
Shortcuts usually aren't...

rastek
Posts: 157
Joined: Wed Aug 06, 2014 12:00 pm

Re: How toContunue after determining not existence of an object

Post by rastek » Thu Oct 23, 2014 4:05 pm

Hey krstc

What you mean True result should be in the top section?
I thought False makes this statement false, thats it
if(Validate.Exists(repo.myApp.dial_pad,0, False))

Maybe I have some typo error but I dont think I need to go and read basic stuff and I dont have time for that.

What I aam trying to do actually must be an easy task (If we think QTP for example)

"Also, if your item exists but is not visible, Ranorex will show it as existing even if you can't see it. "

Hey please dont tell me basic stuff I know difference between existence and visible
I did nt ask you that, different questions

I wrote there is no easy way for handling not visible and not exist objects in ranorex..

still cant understand why there is not a direct way to do in Ranorex !

bcos I have different situations here but none of them working, some of them is not visible some of them not exist, in both situations Ranorex fail actually

Alex and you say I should use my first RepoItemInfo.Exists() method

but it is not working as I expected .. and thats why am I asking on this forum ..:)

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: How toContunue after determining not existence of an object

Post by krstcs » Thu Oct 23, 2014 5:34 pm

I apologize if I am misunderstanding.

How is RepoItemInfo.Exist() not working? Maybe your expectations are incorrect? All it does is say whether the object with the given XPath exists.

if (myRepoItemInfo.Exists()) {
//do stuff for Exists == TRUE here
} else {
//do stuff for Exists == FALSE here
}


Same thing for Validate.Exists(...), except that the "false" in the method call tells Ranorex only that it shouldn't fail if the validation fails, the logic still is TRUE for exists and FALSE for not exists:

if (Validate.Exists(myRepoItemInfo, 0, false)) {
//do stuff for Exists == TRUE here
} else {
//do stuff for Exists == FALSE here
}
Shortcuts usually aren't...

rastek
Posts: 157
Joined: Wed Aug 06, 2014 12:00 pm

Re: How toContunue after determining not existence of an object

Post by rastek » Fri Oct 24, 2014 8:28 am

Hi krstsc
Again thanks for replying, this time it works I think I am getting somewhere but still need something more.

Is it possible to make it true when it is visible instead of just existing ? I tried but can not succeed cos there is not visible property for info object.

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: How toContunue after determining not existence of an object

Post by krstcs » Fri Oct 24, 2014 1:15 pm

Yes, if you add the visible attribute to your XPath like this:

"/a[@innertext='My Link' and @visible='true']"

This path will only be found if the atag is visible.

Remember, you can have more than 1 object for the same element.


MyLinkATag_Visible => "/a[@innertext='My Link' and @visible='true']"
MyLinkATag => "/a[@innertext='My Link']"

Both repo items point to the same atag, but the first one will only be found when the atag is visible and the second will always be found. Just use the one that is most appropriate for whatever you are trying to do.
Shortcuts usually aren't...

rastek
Posts: 157
Joined: Wed Aug 06, 2014 12:00 pm

Re: How toContunue after determining not existence of an object

Post by rastek » Mon Nov 03, 2014 4:03 pm

Thanks krstsc that realy helped ! :wink:

rastek
Posts: 157
Joined: Wed Aug 06, 2014 12:00 pm

Re: How toContunue after determining not existence of an object

Post by rastek » Thu Nov 27, 2014 9:26 am

Hi
This method works fine for objects inside the browser but not working for chrome objects

if (repo.MySiteWebGoogleChrome.AllowInfo.Exists())

Ranorex fails when the object is not there. Path for the Chrome Allow button

container[@accessiblename='Google Chrome']//button[@accessiblename='Allow']/text[@accessiblename='Allow']

can you help me for this ?

Thanks,
Rastek.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How toContunue after determining not existence of an object

Post by Support Team » Fri Nov 28, 2014 10:12 am

Hello Rastek,

Unfortunately, we cannot reproduce your issue.
Which error message do you get?

Kind regards,
Robert
.
Image