Page 1 of 1

Mouse moving to top left after page load/2nd iteration

Posted: Fri Feb 07, 2014 10:39 pm
by tgagel
Hello.

I am trying to iterate through a web page which has menu bar with options underneath. While initially creating the code I had the mouse pointer move to where I needed it to go (no clicks, just mouse moves) and it worked fine. After changing the code such that the submenu items are clicked, the first iteration works but on the 2nd (and subsequent) iterations the mouse pointer move to the top left of the browser instead of to the menu bar item (which is visible and available). I read another posting about this (http://www.ranorex.com/forum/mouse-move ... t5284.html) and it talked about ensuring that caching is off for the repo items. I confirmed that the root folder in my repository is (and I suppose always was been) set to Use Cache = False.

Any ideas? My code is below in case that helps.

Thanks.

Code: Select all

        public void NavigateToVisiblePages()
        {
        	Mouse.DefaultMoveTime = 300;
        	Keyboard.DefaultKeyPressTime = 100;
        	Delay.SpeedFactor = 1.0;
        	
        	var mainNav = repo.EnCompass.MenuBarNavigation.MainNav;
        	
        	IList<Ranorex.SpanTag> myMainMenu = mainNav.Find <Ranorex.SpanTag>(".//div[@class='mainMenuItemNew']/?/?/span");
        	
        	// Using this for loop instead of ForEach as the elements are in the list backwards
        	// Uses "i>=1" so that the Help menu, which is indexed 0, isn't included
        	for (int i = myMainMenu.Count - 1; i >= 1; i--)
        		{	
        			Ranorex.SpanTag menuitem = myMainMenu[i];
        			menuitem.MoveTo();
        			
        			string MainNavName = Regex.Replace(menuitem.ToString(), "SpanTag:", string.Empty);
        			//Report.Info("menuitem " + menuitem);
        			//Report.Info("MainNavName " + MainNavName);
        			
        			//Ranorex.Report.Screenshot (menuitem);
        			Delay.Milliseconds(200);
            		//repo.EnCompass.MenuBarNavigation.MainNav.PerformClick();
            		
            		//Getting drop down items underneath main
            		var subNav = repo.EnCompass.MenuBarNavigation.SubNavItems;
        	
					IList<Ranorex.ATag> mySubMenu = mainNav.Find <Ranorex.ATag>(".//div[@id~'ctl00_MainMenu2_.*']/../div[@class!='mainMenuItemNew' and @visible='True']/*");
        			
					Report.Info ("Count : " + mySubMenu.Count.ToString());
            		
            		foreach (Ranorex.ATag submenuitem in mySubMenu)
        			{	
        				//submenuitem.MoveTo();
        				
        				string SubMenuName = Regex.Replace(submenuitem.ToString(), "ATag:", string.Empty);
        				
        				// Report where we navigated to to the Report
        				Report.Info(MainNavName + " - " + SubMenuName);

        				Delay.Milliseconds(200);
            			
        				// This and the rest worked when the command was MoveTo instead (no page load)
        				submenuitem.PerformClick();
        				
        				// Wait for page load
        				Delay.Seconds(10);
        				
        				// The menuitem value is still correct
        				Report.Info("menuitem: " + menuitem);
						
        				// When this happens, the cursor moves to the top left instead of the menu item
        				menuitem.MoveTo();
            			
            			Delay.Seconds(5);
        			}
            		
            		
            		
        		}

Re: Mouse moving to top left after page load/2nd iteration

Posted: Mon Feb 10, 2014 3:29 pm
by krstcs
What version of Ranorex are you using?

What browser are you testing in?

Can you post a snapshot of your application? See this page for information on how to create snapshots:
http://www.ranorex.com/support/user-gui ... files.html

Re: Mouse moving to top left after page load/2nd iteration

Posted: Mon Feb 10, 2014 4:26 pm
by tgagel
Thanks for the reply.

We are using Ranorex version 4.1.4 and we are testing (and the test fails in) Firefox 26.0 and IE10.

Unfortunately I won't be able to post a snapshot (it's a web app and I'm not comfortable posting its' information to a public forum) but perhaps I can get that info to Ranorex support.

If there are any general thoughts on this I'd appreciate any ideas.

Thanks.

Todd

Re: Mouse moving to top left after page load/2nd iteration

Posted: Wed Feb 26, 2014 5:01 pm
by tgagel
For some reason, even though the rxpath was the same, it could no longer find the element after page load. The answer was that the lists needed to be reloaded after each page load. Code snippit below. Thanks to Robert at Ranorex Support for the assistance with this. Hopefully this can help someone else as well.

Code: Select all

///////////////////////////////////////////////////////////////////////////////
//
// This file was automatically generated by RANOREX.
// Your custom recording code should go in this file.
// The designer will only add methods to this file, so your custom code won't be overwritten.
// http://www.ranorex.com
// 
///////////////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Threading;
using WinForms = System.Windows.Forms;

using Ranorex;
using Ranorex.Core;
using Ranorex.Core.Testing;

namespace MyApp.SmokeTest
{
	public partial class SmokeTest
	{
		//Attributes
		private DivTag mainNav;
		private IList<SpanTag> myMainMenu;
		private IList<DivTag> myMainMenuHelper;

		/// <summary>
		/// This method gets called right after the recording has been started.
		/// It can be used to execute recording specific initialization code.
		/// </summary>
		private void Init()
		{
			loadMainMenuData();
			// Your recording specific initialization code goes here.
		}

		public void NavigateThroughMenus()
		{
        	Mouse.DefaultMoveTime = 100;
        	Keyboard.DefaultKeyPressTime = 100;
        	Delay.SpeedFactor = 1.0;
 
        	// Iterate
			for (int i = myMainMenu.Count - 1; i >= 1; i--)
			{
				SpanTag menuitem = myMainMenu[i];
				
				// Get Main Menu Name
				string MainNavName = Regex.Replace(menuitem.ToString(), "SpanTag:", string.Empty);
				
				menuitem.MoveTo();
				
				// Get all submenus from a specific main menu
				IList<ATag> mySubMenu  = myMainMenuHelper[i].FindDescendants<ATag>();
				
				// Iterate over submenus
				for (int j = 1; j < mySubMenu.Count; j++ ) 
				{
					// Get fresh list
					IList<ATag> mySubMenuHelper  = this.myMainMenuHelper[i].FindDescendants<ATag>();
					
					ATag submenuItem = mySubMenuHelper[j];
					
					// Get Sub Menu Name
					string SubMenuName = Regex.Replace(submenuItem.ToString(), "ATag:", string.Empty);
					
					// Report where we navigated to
					Report.Info(MainNavName + " - " + SubMenuName);
					
					submenuItem.MoveTo();
					submenuItem.PerformClick();
					
					// Wait for page load to complete
					
					// ReloadLists
					loadMainMenuData();
					
					// Get fresh list
					SpanTag menuitemHelper = this.myMainMenu[i];
					menuitemHelper.MoveTo();
				}
			}
		}
		
		private void loadMainMenuData()
		{
			// Menu container
			this.mainNav = repo.MyApp.MenuBarNavigation.MainNav;
			// Get all span tags
			this.myMainMenu = mainNav.FindDescendants<SpanTag>();
			// Get all div tags in Ilist
			this.myMainMenuHelper = mainNav.FindDescendants<DivTag>();
		}
	}
}
Todd