Increasing the time to find a web element

Ask general questions here.
mirih87
Posts: 11
Joined: Tue Jul 08, 2014 1:54 pm

Increasing the time to find a web element

Post by mirih87 » Sun Jul 27, 2014 12:31 pm

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

User avatar
testautomator
Posts: 67
Joined: Fri Oct 25, 2013 6:37 am
Location: Bangalore, India

Re: Increasing the time to find a web element

Post by testautomator » Mon Jul 28, 2014 5:54 am

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?

mirih87
Posts: 11
Joined: Tue Jul 08, 2014 1:54 pm

Re: Increasing the time to find a web element

Post by mirih87 » Mon Jul 28, 2014 7:57 am

It is already there.(not dynamic)

User avatar
testautomator
Posts: 67
Joined: Fri Oct 25, 2013 6:37 am
Location: Bangalore, India

Re: Increasing the time to find a web element

Post by testautomator » Mon Jul 28, 2014 8:09 am

Then I suggest not using timeout in FindSingle and fine tune the xpath. Try building a faster xpath.

mzperix
Posts: 137
Joined: Fri Apr 06, 2012 12:19 pm

Re: Increasing the time to find a web element

Post by mzperix » Thu Jul 31, 2014 11:15 am

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