Forum Discussion

SlickRick's avatar
SlickRick
Contributor
22 days ago
Solved

Taking Picture of a control/window with expanded combo box

Hi all,

i was writing a test where i need to take a screenshot of the window and save it to disk.

It works well except that in the screenshot im taking, i have an expander combobox where i can see all the items listed in there.

I would like to include this inside my screenshot, however when i do my TheWindow.Picture() it closes the combobox when taking the screenshot.

I was wondering how i can ensure that the screenshot includes this expanded combobox.

During the playback of tests, i see that TestComplete is able to take screenshot of controls and there expanded lists, so im guessing it must be possible?

Thank you for any help!

  • Not sure if it makes a difference but it is for a Desktop application and not a web.

    I managed to make it work (not perfectly) using Desktop.Picture and using the control bounds.

    Here is the script i use:

    function takeScreenshotAndSave(control, folderPath, fileName) {
        try {
            // Validate the input parameters to ensure they are not undefined or null
            if (!control || !folderPath || !fileName) {
                throw new Error("Control or file path or file path is undefined.");
            }
            
            // Take a screenshot of the control. The Picture() method captures the control's current visual state.
            var picture = Sys.Desktop.Picture(control.Left,control.Top,control.Width,control.Height,false);
             //control.Picture(control.Left,control.Top,control.Width,control.Height,false);
            var fullPath =folderPath + "\\" + fileName;
            
            IOOperations.CreateFolderIfDoesntExist(folderPath);
            
             // Save the captured image to the specified file path.
            // The SaveToFile method takes the full path, including the file name and extension, as its argument.
            if (picture.SaveToFile(fullPath)){
              
            // Log a message indicating the screenshot was saved successfully.
            // This is useful for debugging and confirmation purposes.
            Log.Message("Screenshot saved successfully to: " + fullPath);
            
            }
          else
            Log.Error("Could not create the picture " + fullPath);
                   
          
        } catch (e) {
            // Handle any errors that occur during the screenshot capture or file saving process.
            // This block logs the error message, which aids in troubleshooting.
            Log.Error("An error occurred while taking a screenshot: " + e.message);
            
            // If needed, rethrow the exception to handle it further up the call stack.
            // Uncomment the line below to rethrow the error.
            // throw e;
        }
    }

    However if i use the commented line #10 instead of 9, the dropdown is closed. 

    It would be nice if there was an option to prevent that.

3 Replies

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    If the control looks likes this, and no other items are shown in the Object Browser, then I don't think it's possible. As it's the browser that draws the UI.

    Other controls such as Bootstrap, you can capture the items of the dropdown 

     

  • Not sure if it makes a difference but it is for a Desktop application and not a web.

    I managed to make it work (not perfectly) using Desktop.Picture and using the control bounds.

    Here is the script i use:

    function takeScreenshotAndSave(control, folderPath, fileName) {
        try {
            // Validate the input parameters to ensure they are not undefined or null
            if (!control || !folderPath || !fileName) {
                throw new Error("Control or file path or file path is undefined.");
            }
            
            // Take a screenshot of the control. The Picture() method captures the control's current visual state.
            var picture = Sys.Desktop.Picture(control.Left,control.Top,control.Width,control.Height,false);
             //control.Picture(control.Left,control.Top,control.Width,control.Height,false);
            var fullPath =folderPath + "\\" + fileName;
            
            IOOperations.CreateFolderIfDoesntExist(folderPath);
            
             // Save the captured image to the specified file path.
            // The SaveToFile method takes the full path, including the file name and extension, as its argument.
            if (picture.SaveToFile(fullPath)){
              
            // Log a message indicating the screenshot was saved successfully.
            // This is useful for debugging and confirmation purposes.
            Log.Message("Screenshot saved successfully to: " + fullPath);
            
            }
          else
            Log.Error("Could not create the picture " + fullPath);
                   
          
        } catch (e) {
            // Handle any errors that occur during the screenshot capture or file saving process.
            // This block logs the error message, which aids in troubleshooting.
            Log.Error("An error occurred while taking a screenshot: " + e.message);
            
            // If needed, rethrow the exception to handle it further up the call stack.
            // Uncomment the line below to rethrow the error.
            // throw e;
        }
    }

    However if i use the commented line #10 instead of 9, the dropdown is closed. 

    It would be nice if there was an option to prevent that.

    • rraghvani's avatar
      rraghvani
      Champion Level 3

      What you have, is probably the best method.

      Like the web behaviour, doing list.Picture, also closes the drop down list and only captures the combo box.