Page 2 of 2

Re: Validate.Exists throws exception

Posted: Thu Aug 20, 2015 7:43 pm
by krstcs
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.

Re: Validate.Exists throws exception

Posted: Thu Aug 20, 2015 10:45 pm
by Support Team
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

Re: Validate.Exists throws exception

Posted: Fri Aug 21, 2015 3:12 pm
by sherinjab
Thanks a lot Alex. That was exactly what I needed and helped me with my scenario.

Regards,
Sherin

Re: Validate.Exists throws exception

Posted: Wed Oct 19, 2016 7:17 am
by donaldsummer
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,

Re: Validate.Exists throws exception

Posted: Fri Oct 21, 2016 3:02 pm
by asdf
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.

Re: Validate.Exists throws exception

Posted: Mon Mar 06, 2017 10:26 pm
by manalitatke
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!

Re: Validate.Exists throws exception

Posted: Tue Mar 07, 2017 8:15 am
by odklizec
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.

Re: Validate.Exists throws exception

Posted: Sun Sep 16, 2018 6:11 am
by Krishman
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";
}

Re: Validate.Exists throws exception

Posted: Mon Sep 17, 2018 8:27 am
by odklizec
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?