Wait for an image to be loaded

Ask general questions here.
mto
Posts: 25
Joined: Tue Jan 06, 2015 10:31 am

Wait for an image to be loaded

Post by mto » Wed Aug 05, 2015 12:13 pm

Hello all,

I am a beginner in programming and i have an issue when i try to create a method which permits to wait for an image is loaded to do another action (a click for example).

This is the c# code i am using but its not working

Code: Select all

public void WaitForImageExists(){
  Ranorex.unknown myElement = null;
  string myPath = "dom/[1] ///div[@id~'panelUploadApplet' and visible='True']

  if (Host.local.TryFindSingle (myPath, 30000, out myElement)
  {
   Validate.compareImage (repo.ExtranetWorkspace.SunAwtCanvas2Infos, SunAwtCanvas2_Screenshot1,  SunAwtCanvas2_Screenshot1_Options);
  }

}
My hope is to wait for "SunAwtCanvas2_Screenshot1" to be loaded before doing another action.
Thank you in advance for your help.

Best regards,
MTO

Fergal
Certified Professional
Certified Professional
Posts: 455
Joined: Tue Feb 18, 2014 2:14 pm
Location: Co Louth, Ireland
Contact:

Re: Wait for an image to be loaded

Post by Fergal » Wed Aug 05, 2015 2:21 pm

In a recorded module you could drag the repository item up from the repository table, to create a Wait For action on it. Alternatively you could add a Wait For action to a recording and then assign a repository item to that Wait For action, as outlined here.

Once you have the action created, you can right click on it and chose the "Convert to User Code" option, to get the code you need.

Hopefully that helps?

mto
Posts: 25
Joined: Tue Jan 06, 2015 10:31 am

Re: Wait for an image to be loaded

Post by mto » Wed Aug 05, 2015 3:44 pm

Thank you for your response Fergal.

I yet tried this but it s not working.

In fact, my test is executing a java applet and this may take random time.
So i have to wait for an image is loaded before doing a click.

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Wait for an image to be loaded

Post by krstcs » Wed Aug 05, 2015 4:00 pm

I think you may have misunderstood what was being asked.

You need to create a Ranorex Repository item that maps to the image you are waiting for and make sure the XPath is both correct and accounts for the element needing to be visible (so add " and @visible='true'" to the path).

Then, you need to drag that repo item into the action table of the recording module and select "Wait For" from the list. This will add a wait action to the table. Choose the 'Exists' state from the drop-down, and give it a timeout that will ensure Ranorex waits long enough (according to your requirements, so if you requirements state that the system should load the image in under 5 min, use 5 min, etc.).

This will tell Ranorex to wait until that element exists and is visible, or until the 5 min are up.


Finally, if you haven't, please read the entire user guide as it contains many examples and explains everything you need to know about using Ranorex. You can find it HERE.
Shortcuts usually aren't...