Page 1 of 1

Increasing the time to find a web element

Posted: Sun Jul 27, 2014 12:31 pm
by mirih87
I am looking for a specific link in a HTML file (for clicking on it).
See the following code:

Code: Select all

public static int DOMClickLink(Ranorex.WebElement webDocumentName, string LinkText)
           {
           	
            ATag DOMlink;
           	 
            //Search for the Link on the page
            try
            {         
                webDocumentName.EnsureVisible();
                Thread.Sleep(500);    
               
                DOMlink=webDocumentName.FindSingle(".//a[@innertext='" + LinkText + "']");
            }

            catch (RanorexException e)
            {
                Report.Error("Unable to find Link: " + LinkText);
                Report.Screenshot();
                Console.WriteLine("Unable to find Link: " + LinkText);
                return -1;
            }

            //Click a Link
            try
            {
                Report.Info("Clicking Link: " + LinkText);
                DOMlink.Focus();
               // Thread.Sleep(500);
                DOMlink.Click(Location.Center);
                Report.Debug("  Clicked Link: " + LinkText);
            }

            catch (RanorexException e)
            {
                Report.Error(e.ToString());
                Report.Screenshot();
                Console.WriteLine(e.ToString());
                return -1;
            }

            return 0;
        } //End DOMClickLink
invoke:
WebDocument webDocument="/dom[@domain='XXXXX']";
Automation.DOMClickLink(webElement ,"Name");

My problem is that It takes a lot of time to find my link element.
This is the RanorexPath for the link above:
/dom[@domain='XXXXX']//tr/td[4]/a[@innertext='XXXX']/../../td[7]/a[@innertext='XXXXX']

How can i increase my time to find my element ?
thanks in advance

Re: Increasing the time to find a web element

Posted: Mon Jul 28, 2014 5:54 am
by testautomator
FindSingle has a duration as a parameter. But if its taking too much time, then you need to fine tune the xpath. Is that link dynamic or is it already there when you are looking for it?

Re: Increasing the time to find a web element

Posted: Mon Jul 28, 2014 7:57 am
by mirih87
It is already there.(not dynamic)

Re: Increasing the time to find a web element

Posted: Mon Jul 28, 2014 8:09 am
by testautomator
Then I suggest not using timeout in FindSingle and fine tune the xpath. Try building a faster xpath.

Re: Increasing the time to find a web element

Posted: Thu Jul 31, 2014 11:15 am
by mzperix
Hi,

I do not know what is Ranorex way of finding fastest, but you can try to use @id=idName attribute, or #idName attribute to find an element in the Xpath.

Finding DOM element can be really slow compared to certain mechanisms. See a comparison on JQuery fin element vs. Browser's native find element: http://jsperf.com/traverse-from-cached- ... d-selector

Best Regards,
Zoltan