Validate.Exists throws exception

Class library usage, coding and language questions.
krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Validate.Exists throws exception

Post by krstcs » Thu Aug 20, 2015 7:43 pm

All I can tell you is to read the API: http://www.ranorex.com/Documentation/Ranorex/

The only Exists() methods in there are on the Validate and RepoItemInfo classes.
Shortcuts usually aren't...

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

Re: Validate.Exists throws exception

Post by Support Team » Thu Aug 20, 2015 10:45 pm

If you want to check for existence of an element without the use of a repository item, i.e. by using a plain RanoreXPath, you can simply search for the item using the TryFindSingle method:
// search the element tree only once for the specified RanoreXPath
Unknown anyElement;
bool anyElementExists = Host.Local.TryFindSingle("/pathToTheElement", out anyElement);

// search continuously until button is found or the timeout is reached
Button button;
var timeoutToSearchForButton = Duration.FromMilliseconds(10000);
bool buttonExists = Host.Local.TryFindSingle("/pathToButton", timeoutToSearchForButton, out button);
Also see the code examples in the user guide:
http://www.ranorex.com/support/user-gui ... html#c3202

Regards,
Alex
Ranorex Team
.
Image

sherinjab
Posts: 23
Joined: Wed Oct 08, 2014 2:57 pm

Re: Validate.Exists throws exception

Post by sherinjab » Fri Aug 21, 2015 3:12 pm

Thanks a lot Alex. That was exactly what I needed and helped me with my scenario.

Regards,
Sherin

donaldsummer
Posts: 1
Joined: Wed Oct 19, 2016 6:58 am

Re: Validate.Exists throws exception

Post by donaldsummer » Wed Oct 19, 2016 7:17 am

Hi,

Splendid day!

I also want to return a boolean for my if condition, my code goes like below:

if(RepoItem.Exist())
{...}

But unfortunately, there is no Exist() method, maybe because of my Ranorex version (6.0.1).
Can you confirm?
If yes, what is the work around for this version?

Best regards,

asdf
Posts: 174
Joined: Mon Mar 21, 2016 3:16 pm

Re: Validate.Exists throws exception

Post by asdf » Fri Oct 21, 2016 3:02 pm

Hello DonnaldSummer!

Repository items have different method and as you said Exists is not one of them. However Ranorex for every repository item stores an information about it in RepoItemInfo class and this class contains method Exists().

So to make your if statement work simly add "Info" at the end of your repository item and call method Exists():

if(RepoItemInfo.Exists())
{...}

Hopefully my answer helps.

manalitatke
Posts: 36
Joined: Mon Jan 16, 2017 3:24 pm

Re: Validate.Exists throws exception

Post by manalitatke » Mon Mar 06, 2017 10:26 pm

Hello,

In reference to the above post, i have a doubt in my use-case.

As specified in the 'demand interval length.png' screenshot attached, i am trying to automate the recording of combo-box items using data-driven approach. However, they do not include all the items of my combobox.

Due to this,i intend to add a Validate.exists function call to ensure each and every item of my combobox will be implemented in automation. However, this throws me an exception and fails my Test.

Instead, i tried Tobias's approach of using
Report.Info("Exists = " + repo.YourAppFolder.YourRepoItemInfo.Exists().ToString());

and considering my repository heirarchy as shown in 'ranorex path.png', i chose the YourRepoItemInfo as ComboboxInfo.

It still throws me an validation error as specified in 'error validate.png'.
Can someone please help me with this?

How can i ensure that i implement all items of my combobox using data driven testing and validating the same using validate.exists method?

Thanks!
Attachments
error validate.PNG
error validate.PNG (4.16 KiB) Viewed 668 times
ranorex path.PNG
ranorex path.PNG (5.92 KiB) Viewed 668 times
demand interval length.PNG
demand interval length.PNG (1.34 KiB) Viewed 668 times

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

Re: Validate.Exists throws exception

Post by odklizec » Tue Mar 07, 2017 8:15 am

Hi,

Please upload a Ranorex snapshot (not screenshot) of the element in question. Screenshot is unfortunately useless. Also, please post exact implementation of Validate.exists in your recording/code module. 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

Krishman
Posts: 1
Joined: Sun Sep 16, 2018 5:56 am

Re: Validate.Exists throws exception

Post by Krishman » Sun Sep 16, 2018 6:11 am

Hello .. I'm pretty new to Ranorex ..I was using below code.
Scenario : I need to check , If the repo Object exists click on it and if it doesn't exist return to calling function.But it always fails when the object is not found .What am i missing here ?Appreciate any help .. Thanks in advance.

if(PerformLevel33(repo.GW_CAA_Auto_Repo1.WebGW.Aggr_Que_Level2.Aggr_Que_L0000Info.Exists().ToString(),repo.GW_CAA_Auto_Repo1.WebGW.Aggr_Que_Level2.Aggr_Que_L0000) == "False") return;

private string PerformLevel3(string summaryObjInfo, SpanTag summaryObjSpan)
{
if(summaryObjInfo="True")
{
summaryObjSpan.Click();
Delay.Duration(3000, false);

Keyboard.Press(System.Windows.Forms.Keys.A | System.Windows.Forms.Keys.Control, 30, Keyboard.DefaultKeyPressTime, 1, true);
Keyboard.Press(System.Windows.Forms.Keys.C | System.Windows.Forms.Keys.Control, 30, Keyboard.DefaultKeyPressTime, 1, true);

//Copy the data from Web to Clip-Board
string Copy_Web = Copy_Clipboard();


//String Index Value to eliminate Non_SQL elements
string Sql_Val = stringIndexval(Copy_Web,Public_Excl_Web);

//Write the SQL to Xls
writeXls(Sql_Val);
//return true;
return Public_Exist;

}
else
{
//return false;
return "False";
}

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

Re: Validate.Exists throws exception

Post by odklizec » Mon Sep 17, 2018 8:27 am

Hi,

I think you are overcomplicating things? Why don't you simply pass the repoitem to method, like this...

Code: Select all

PerformLevel33(RepoItemInfo summaryObjInfo, ...)
And then change the 'exists' condition in PerformLevel3 method like this:

Code: Select all

if(summaryObjInfo.Exists())
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