Internet Explorer 8 MenuBar Problem?

Jan 30, 2011 at 6:48 PM

Hello all,

I'm making an application that manipulates the common web-browser Internet Explorer 8 and I am having some problems.

I'm trying to go to(in IE) Tools>Internet Options so I used the code given here:"http://white.codeplex.com/wikipage?title=MenuBar%2c%20Menu%20and%20PopupMenu&referringTitle=Programming%20using%20white"

code snippet of mine:

 MenuBar menuBar = window.MenuBar;
 Menu level2Menu = menuBar.MenuItem("Tools","Internet Options...");
 level2Menu.Click();

and this code clicks on the 'Tools' button and then crashes and gives me the error:

"Error invoking MenuBar.MenuItem"

Help???

Thanks SO much

Jan 31, 2011 at 6:39 AM

Hi

can you try to use UIAutomation (InvokePattern) instead of Click()?

call InvokePattern(level2Menu);

 

/// <summary>
/// Gets the specified pattern.
/// </summary>
/// <param name="element">The element.</param>
/// <param name="value">The value.</param>
/// <returns></returns>
public static AutomationPattern GetSpecifiedPattern(AutomationElement element, string value)
{
  AutomationPattern[] supportedPattern = element.GetSupportedPatterns();

  AutomationPattern automationValuePattern = null;
  foreach (AutomationPattern pattern in supportedPattern)
  {
	if (pattern.ProgrammaticName == value)
	{
	  automationValuePattern = pattern;
	  break;
	}
  }
  return automationValuePattern;
}

/// <summary>
/// Invoke the automation element 
/// </summary>
/// <param name="element">The element</param>
public static void InvokePattern(AutomationElement element)
{
  AutomationPattern automationPatternFromElement = GetSpecifiedPattern(element, "InvokePatternIdentifiers.Pattern");
  if (automationPatternFromElement != null)
  {
	InvokePattern invokePattern = (InvokePattern) element.GetCurrentPattern( automationPatternFromElement );
	Assert.IsNotNull( invokePattern, "InvokePattern cannot be found" );
	invokePattern.Invoke();
  }
}

 

 

Throndorin