How to click "Ok" via Scripting when a Pop up appears when opening a Workbench project?

Rohith Patchigolla
Rohith Patchigolla Member, Moderator, Employee Posts: 186
100 Comments 25 Answers Second Anniversary 25 Likes
✭✭✭✭

Sometimes when opening a Workbench project, one might get some popups (example shown below). When automating workflows in WB, this pop up will block the automation and one would need to manually click on Ok in the pop up for the automation to proceed. How to get rid of this Pop up or click on Ok via Scripting?

Comments

  • Rohith Patchigolla
    Rohith Patchigolla Member, Moderator, Employee Posts: 186
    100 Comments 25 Answers Second Anniversary 25 Likes
    ✭✭✭✭

    One could try using Windows API to interact with GUI elements. The below solution seems to work.

    The code can be saved as .py file and can be run in WB scripting console (WB --> File --> Scripting --> Run Script File). This code will basically open a Workbench project saved in a specified path and clicks on Ok if any pop up appears.

    Open(FilePath="D:/del/test_popup.wbpj")
    
    #Provide the title of the Popup Window.
    Popup_Window_Title = 'Warning'
    
    # Function to find the OK button and click it
    def click_ok_button(window_title):
        import clr
        clr.AddReference('UIAutomationClient')
        clr.AddReference('UIAutomationTypes')
    
        from System.Windows.Automation import AutomationElement, TreeScope, Condition, PropertyCondition, ControlType
        from System.Windows.Automation import Automation
        # Get the desktop element
        desktop = AutomationElement.RootElement
    
        # Condition to find the window with the specified title
        condition = PropertyCondition(AutomationElement.NameProperty, window_title)
        window = desktop.FindFirst(TreeScope.Children, condition)
    
        if window is not None:
            # Condition to find the OK button
            button_condition = PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button)
            button = window.FindFirst(TreeScope.Descendants, button_condition)
    
            if button is not None:
                # Invoke the button's click event
                invoke_pattern = button.GetCurrentPattern(InvokePattern.Pattern)
                invoke_pattern.Invoke()
    
    click_ok_button(Popup_Window_Title)