not able to find object

Ask general questions here.
sdimbre
Posts: 21
Joined: Wed Sep 07, 2011 12:38 pm

not able to find object

Post by sdimbre » Mon Apr 30, 2012 8:39 am

Hello Sir/Madam,

I have written a method 'isObjectExists' to verify object exists or not which should return me object if exists and null if object does not exists. Please see below.

public Ranorex.Adapter isObjectExists(string xPath, Duration timeOut, Ranorex.Adapter obj)
{
if (Host.Local.TryFindSingle(xPath, timeOut, out obj))
{
return obj;
}
else
{
return null;
}
}

and call to above method is "Ranorex.WebDocument doc = (Ranorex.WebDocument)isObjectExists(xPath, 90000, document)"

but problem is that this method is not able to find object and always returning me null(). Instead if I use following(WebDocument instead of Adapter) it is working but then this
will be specific to WebDocment and not will be generic method.

public Ranorex.WebDocument isObjectExists(string xPath, Duration timeOut, Ranorex.WebDocument obj)
{
if (Host.Local.TryFindSingle(xPath, timeOut, out obj))
{
return obj;
}
else
{
return null;
}
}

call to above is "Ranorex.WebDocument doc = isObjectExists(xPath, 90000, document)"

Thanks,

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

Re: not able to find object

Post by Support Team » Mon Apr 30, 2012 11:01 am

Hello,

I would use the following code:
private void Init()
    {
      // Your recording specific initialization code goes here.
      Element document;
      bool wasFound = isObjectExists("/dom[@domain='orf.at']", 90000, out document);
      Report.Info("Element document: "+document.As<Ranorex.WebDocument>().Domain);

    }
    
    public bool isObjectExists(string xPath, Duration timeOut, out Element obj)
    {
      return Host.Local.TryFindSingle(xPath, timeOut, out obj);
    }
Regards,
Markus
Ranorex Support Team
.
Image