Menu

Save Screenshot?

Help
Anonymous
2012-06-21
2012-06-21
  • Anonymous

    Anonymous - 2012-06-21

    Hi, one more question... sorry!

    Driver.getScreenshot() does not seem to save any file on HDD.

    Do you know how to retrieve the screenshot on local HDD?

    Many Thanks!

     
  • oh!

    oh! - 2012-06-21

    Hi,

    Yes, it is possible. Try this:

    Sub Include(ByVal strFile)
       Set objFs = CreateObject("Scripting.FileSystemObject")
       Set WshShell = CreateObject("WScript.Shell")
       strFile = WshShell.ExpandEnvironmentStrings(strFile)
       file = objFs.GetAbsolutePathName(strFile)
       Set objFile = objFs.OpenTextFile(strFile)
       strCode = objFile.ReadAll
       objFile.Close
       ExecuteGlobal(strCode)
    End Sub
    
    Const TypeBinary = 1
    Const ForReading = 1, ForWriting = 2, ForAppending = 8
    outFile = "image.png"
    
    Include "WebDriver.vbs"
    
    
    private function decodeBase64(base64)
      dim DM, EL
      Set DM = CreateObject("Microsoft.XMLDOM")
      Set EL = DM.createElement("tmp")
      EL.DataType = "bin.base64"
      EL.Text = base64
      decodeBase64 = EL.NodeTypedValue
    end function
    
    private Sub writeBytes(file, bytes)
      Dim binaryStream
      Set binaryStream = CreateObject("ADODB.Stream")
      binaryStream.Type = TypeBinary
      binaryStream.Open
      binaryStream.Write bytes
      binaryStream.SaveToFile file, ForWriting
    End Sub
    
    Set Driver = New WebDriver
        Driver.connect "127.0.0.1","4444","internet explorer", ""
        Driver.navigateTo "http://www.google.com"       
        image = decodeBase64(Driver.getScreenshot())    
            writeBytes outFile, image
    

    Best regards,
    Oscar Henry.

     
  • Anonymous

    Anonymous - 2012-06-21

    Great you saved my life!

    Thanks, and congrats for your work, long life to your project and to wsh :)

     
  • oh!

    oh! - 2012-06-21

    Thank for your interest in this project and for your help.

    Best regards
    Oscar Henry.

     

Anonymous
Anonymous

Add attachments
Cancel