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
How toContunue after determining not existence of an object
Re: How toContunue after determining not existence of an object
Hi ,
Try to use this code...
Basically, it should validate the element without throwing exception (it sets exceptionOnFail to false). Hope this helps?
Try to use this code...
Code: Select all
if(Validate.Exists(repo.myApp.Http47168150628580Imag1Info,null, false))
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
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
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: How toContunue after determining not existence of an object
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
Regards,
Alex
Ranorex Team
Re: How toContunue after determining not existence of an object
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?
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?
Re: How toContunue after determining not existence of an object
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..
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..
Re: How toContunue after determining not existence of an object
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.
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...
Re: How toContunue after determining not existence of an object
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 ..
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 ..

Re: How toContunue after determining not existence of an object
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
}
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...
Re: How toContunue after determining not existence of an object
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.
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.
Re: How toContunue after determining not existence of an object
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.
"/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...
Re: How toContunue after determining not existence of an object
Thanks krstsc that realy helped ! 

Re: How toContunue after determining not existence of an object
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.
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.
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: How toContunue after determining not existence of an object
Hello Rastek,
Unfortunately, we cannot reproduce your issue.
Which error message do you get?
Kind regards,
Robert
Unfortunately, we cannot reproduce your issue.
Which error message do you get?
Kind regards,
Robert