def press_ok_button(ui):

    if is_current_backend_wx():
        import wx

        ok_button = ui.control.FindWindowByName('button')
        click_event = wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED,
                                      ok_button.GetId())
        ok_button.ProcessEvent(click_event)

    elif is_current_backend_qt4():
        from pyface import qt

        # press the OK button and close the dialog
        ok_button = ui.control.findChild(qt.QtGui.QPushButton)
        ok_button.click()
Press the OK button in a wx or qt dialog.
dataset/ETHPy150Open enthought/traitsui/traitsui/tests/_tools.py/press_ok_button