Class: OperaWatir::QuickMenuItem

Inherits:
QuickWidget show all
Defined in:
lib/operawatir/quickwidgets/quick_menuitem.rb

Constant Summary

Constants inherited from QuickWidget

OperaWatir::QuickWidget::ConditionTimeout

Instance Method Summary collapse

Methods inherited from QuickWidget

#click_with_condition, #double_click_with_condition, #enabled?, #exist?, #focus_with_click, #focus_with_hover, #has_ui_string?, #middle_click_with_condition, #open_menu_with_rightclick, #open_window_with_hover, #parent_name, #position, #quick_tabs, #quick_widgets, #right_click_with_condition, #type, #value, #verify_includes_text, #verify_text, #visible?, #widget_info_string

Methods included from DesktopContainer

#quick_addressfield, #quick_button, #quick_checkbox, #quick_dialogtab, #quick_dropdown, #quick_dropdownitem, #quick_editfield, #quick_find, #quick_griditem, #quick_gridlayout, #quick_label, #quick_menu, #quick_menuitem, #quick_radiobutton, #quick_searchfield, #quick_tab, #quick_thumbnail, #quick_toolbar, #quick_treeitem, #quick_treeview, #quick_window

Instance Method Details

#actionObject

Returns the name of the action this item executes when selected.

Returns:

  • the name of the action this item executes when selected



146
147
148
# File 'lib/operawatir/quickwidgets/quick_menuitem.rb', line 146

def action
  element.getActionName()
end

#action_item?Boolean

Returns true if this item is a command/action item.

Returns:

  • (Boolean)

    true if this item is a command/action item



95
96
97
# File 'lib/operawatir/quickwidgets/quick_menuitem.rb', line 95

def action_item?
  action.length > 0
end

#action_paramsObject

Returns the parameters to the action that will be used for the action executed for this item when it is selected.

Returns:

  • the parameters to the action that will be used for the action executed for this item when it is selected



155
156
157
# File 'lib/operawatir/quickwidgets/quick_menuitem.rb', line 155

def action_params
  element.getActionParameter()
end

#bold?Boolean

Returns true if this menuitem has bold text, otherwise false.

Returns:

  • (Boolean)

    true if this menuitem has bold text, otherwise false



79
80
81
# File 'lib/operawatir/quickwidgets/quick_menuitem.rb', line 79

def bold?
  element.isBold()
end

#checked?Boolean

Returns true if element is a checkbox item that is checked, else false.

Returns:

  • (Boolean)

    true if element is a checkbox item that is checked, else false



71
72
73
# File 'lib/operawatir/quickwidgets/quick_menuitem.rb', line 71

def checked?
  element.isChecked()
end

#close_menu_with_click(menu_name) ⇒ Object

Clicks item and waits for the menu to close

Returns:

  • name of menu closed



331
332
333
334
335
# File 'lib/operawatir/quickwidgets/quick_menuitem.rb', line 331

def close_menu_with_click(menu_name)
  wait_start
  click
  wait_for_menu_closed(menu_name)
end

#close_menu_with_key_press(menu_name, key, *modifiers) ⇒ Object

Clicks item and waits for the menu to close

Returns:

  • name of menu closed



296
297
298
299
300
# File 'lib/operawatir/quickwidgets/quick_menuitem.rb', line 296

def close_menu_with_key_press(menu_name, key, *modifiers)
  wait_start
  key_press_direct(key, *modifiers)
  wait_for_menu_closed(menu_name)
end

#heightObject

Returns height of the menuitem.

Returns:

  • height of the menuitem



182
183
184
# File 'lib/operawatir/quickwidgets/quick_menuitem.rb', line 182

def height
  element.getRect().height
end

#load_page_with_clickint

Clicks the button, and waits for loading to finish

Returns:

  • (int)

    Window ID of the window shown or 0 if no window is shown

Raises:



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/operawatir/quickwidgets/quick_menuitem.rb', line 248

def load_page_with_click
  if mac_internal?
    wait_start
    press_menu
    wait_for_menu_pressed
    wait_start
    # Just wait for the load
    wait_for_window_loaded("")
  else
    wait_start
    click
    # Just wait for the load
    wait_for_window_loaded("")
  end
end

Returns name of the menu this menuitem is part of.

Examples:

browser.quick_menu(:name, "Browser File Menu").quick_menuitem(:text, "Open File").menu

Returns:

  • name of the menu this menuitem is part of



52
53
54
# File 'lib/operawatir/quickwidgets/quick_menuitem.rb', line 52

def menu
  element.getMenu()
end

#nameObject

Returns the name of the menuitem. The name is either the action name of the action the item performs, or the name of the submenu the item opens. If the item is a separator, the name is “Separator”

Examples:

(RSpec)

menuitem.name.should == "Separator"
menuitem.name.should == "Close page" #action
menuitem.name.should == "Toolbar Popup Customize Menu" #submenu

Returns:

  • name of menuitem



40
41
42
# File 'lib/operawatir/quickwidgets/quick_menuitem.rb', line 40

def name
  element.getName();
end

#open_menu_with_click(menu_name) ⇒ Object

Clicks the item, and waits for the menu with menu with name menu_name to be shown

Parameters:

  • name (String)

    of menu that should open

Returns:

  • name of menu opened if it matches menu_name (or if menu_name is “”), otherwise returns empty string

Raises:



314
315
316
317
318
319
320
321
322
323
324
# File 'lib/operawatir/quickwidgets/quick_menuitem.rb', line 314

def open_menu_with_click(menu_name)
  if mac_internal?
    wait_start
    press_menu
    wait_for_menu_pressed
  else
    wait_start
    click
    wait_for_menu_shown(menu_name)
  end
end

#open_menu_with_hover(menu_name) ⇒ Object

Hovers the menuitem and waits for the menu with menu_name to open

Examples:

menu.quick_menuitem(:submenu, "Toolbar Popup Customize Menu").open_menu_with_hover("Toolbar Popup Customize Menu")

Parameters:

  • name (String)

    of menu that will open

Returns:

  • name of menu opened if it matches menu_name parameter, otherwise returns the empty string



207
208
209
210
211
212
213
214
215
216
217
# File 'lib/operawatir/quickwidgets/quick_menuitem.rb', line 207

def open_menu_with_hover(menu_name)
  if mac_internal?
    wait_start
    press_menu
    wait_for_menu_pressed
  else
    wait_start
    element.hover
    wait_for_menu_shown(menu_name)
  end
end

#open_window_with_click(win_name) ⇒ int Also known as: open_dialog_with_click

Clicks the button, and waits for the window with window name win_name to be shown

Parameters:

  • win_name (String)

    name of the window that will be opened (Pass a blank string for any window)

Returns:

  • (int)

    Window ID of the window shown or 0 if no window is shown

Raises:



275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/operawatir/quickwidgets/quick_menuitem.rb', line 275

def open_window_with_click(win_name)
  if mac_internal?
    wait_start
    press_menu
    wait_for_menu_pressed
    wait_start
    wait_for_window_shown(win_name)
  else
    wait_start
    click
    wait_for_window_shown(win_name)
  end
end

#posObject

browser.quick_menu(:name, “Browser Tools Menu”).quick_menuitem(:pos, 2).name.should == “Separator”

Returns:

  • position of this menuitem within the menu, also counting separators



138
139
140
# File 'lib/operawatir/quickwidgets/quick_menuitem.rb', line 138

def pos
  element.getRow()
end

#separator?Boolean

Returns true if this menuitem is a separator, else false.

Returns:

  • (Boolean)

    true if this menuitem is a separator, else false



87
88
89
# File 'lib/operawatir/quickwidgets/quick_menuitem.rb', line 87

def separator?
  element.isSeparator()
end

#shortcutObject

browser.quick_menuitem(:action, “Close page”).shortcut # Ctrl+W

Returns:

  • the shortcut of this menuitem as a string



127
128
129
# File 'lib/operawatir/quickwidgets/quick_menuitem.rb', line 127

def shortcut
  element.getShortcut()
end

#shortcutletterObject

(Note: not used on mac, so not a platform dependant feature)

Examples:

(t is shortcutletter to open submenu below)

addressfield.open_menu_with_rightclick("Toolbar Edit Item Popup Menu")
browser.open_menu_with_key_press("Toolbar Popup Customize Menu", "t")

Returns:

  • shortcutletter of this menuitem (typing this letter while the menu is open, will select the item)



117
118
119
# File 'lib/operawatir/quickwidgets/quick_menuitem.rb', line 117

def shortcutletter
  element.getShortcutLetter()
end

(Note: an item will either have a submenu, or an action)

Returns:

  • the name of the submenu this item opens



165
166
167
# File 'lib/operawatir/quickwidgets/quick_menuitem.rb', line 165

def submenu
  element.getSubMenu()
end

Returns true if this menuitem opens a submenu, otherwise false.

Returns:

  • (Boolean)

    true if this menuitem opens a submenu, otherwise false



103
104
105
# File 'lib/operawatir/quickwidgets/quick_menuitem.rb', line 103

def submenu_item?
  element.hasSubMenu()
end

#textObject

(Note: this should normally not be used to access the item, as it will

be language dependent)

Returns:

  • the text of this menu item



63
64
65
# File 'lib/operawatir/quickwidgets/quick_menuitem.rb', line 63

def text
  element.getText()
end

#to_sObject



235
236
237
# File 'lib/operawatir/quickwidgets/quick_menuitem.rb', line 235

def to_s
  "QUICKMENUITEM #{name}, pos #{pos}, menu #{menu}, rect: #{x}, #{y}, #{width}, #{height}, checked? #{checked?}, pos #{pos}, acckey #{shortcutletter}, #{shortcut unless shortcut.nil?}, separator #{separator?}"
end

#toggle_with_clickObject

Use to toggle a checkbox or radio item menuitem



222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/operawatir/quickwidgets/quick_menuitem.rb', line 222

def toggle_with_click
  if mac_internal?
    wait_start
    press_menu
    wait_for_menu_pressed
  else
    click

    # Cheat since we don't have an event yet
    sleep(0.1)
  end
end

#widthObject

Returns width of the menuitem.

Returns:

  • width of the menuitem



174
175
176
# File 'lib/operawatir/quickwidgets/quick_menuitem.rb', line 174

def width
  element.getRect().width
end