Forum Discussion

TanIlak's avatar
TanIlak
Contributor
2 years ago

Log Functions

Hi

I am trying to display the google logo in log file using Log.Picture() method

>> var img=page.FindElement("xpath");

Log.Picture(img);

 

In this way but it's not printing in log.

Am I did any mistake or how to print that logo in log file.

 

Thanks in Advance

10 Replies

  • KB1's avatar
    KB1
    Champion Level 2

     

    The Log.Picture method  allows you to log a picture of an object or a screen region to the test log. You can use this method to log images of controls, windows, web page elements, or any other object that is displayed on the screen.

    To log a picture of a web page element using the Log.Picture method, you can use the following code:

     

     

    var img = page.FindElement("xpath");
    
    // Get the object's rectangle
    var rect = img.GetRectangle();
    
    // Log the picture
    Log.Picture(rect);

     

    This will log a picture of the web page element specified by the XPath expression to the test log.

    Keep in mind that in order for the Log.Picture method to work correctly, the object or screen region that you want to log a picture of must be visible on the screen at the time the method is called. If the object is not visible, the method will not be able to capture a picture of it.

    I hope this helps! Let me know if you have any other questions.

    • TanIlak's avatar
      TanIlak
      Contributor

      Hi KB1,

      Thanks for your response

      >>No, it's not worked for me. Shows error

      unable to find the object rectangle.

      Get Rectangle object does not exist

      Invalid Parameter

       

      >>code for get google logo

      var img=page.FindElement("//img[@class='lnXdpd'");

      var rect=img.GetRectangle();

      Log.picture(rect);

       

       

      Let me know

       

      Thanks in Advance

       

       

  • KB1's avatar
    KB1
    Champion Level 2

    Sorry I was confused with another program. Here is the right solution.

     

    To display the Google logo in the log file using the Log.Picture() method, you need to make sure that you are passing the correct element to the method.

    Here is an example of how you can display the Google logo in the log file:

    1. First, use the TestComplete DOM methods to find the Google logo element on the page. For example, you can use the "FindElement" method to search for the element using its xpath or any other attribute.

    2. Once you have found the element, you can use the "GetImage" method to get the image of the element as a bitmap.

    3. Finally, pass the bitmap to the Log.Picture() method to display it in the log file.

    Here is an example code snippet that demonstrates how to do this:

    // Find the Google logo element
    var logoElement = page.FindElement("xpath", "//img[@title='Google']", 10);
    
    // Get the image of the logo element as a bitmap
    var logoImage = logoElement.GetImage();
    
    // Display the logo image in the log file
    Log.Picture(logoImage);


     

    • TanIlak's avatar
      TanIlak
      Contributor

      Hi KB1,

      I have tried with GetImage() method also, the same error previous I have posted only am getting. What to do??

      • KB1's avatar
        KB1
        Champion Level 2

        Is the logo on the page?

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Providing your search condition is correct, it works fine.

     

    • TanIlak's avatar
      TanIlak
      Contributor

      Oh, for me it shows invalid number of parameters. I will check