Skip to main content

UFT - Take full page screenshot by scrolling the page


'########################################################################################
'This is navigate through the full page and taking individual screenshot of visible area
'########################################################################################
Function TakeScreenshot
 Dim intScrolls, intScroll, strScrollPos
 Set pgApp = Browser("").Page("")

 intScrolls = Round(pgApp.RunScript("document.documentElement.scrollHeight / (screen.height)"), 2)
 If intScrolls < 1 Then intScrolls = -1

 pgApp.RunScript "window.scrollTo(0, 0);"
 Wait 1
 Browser("").CaptureBitmap "C:\screenshot0.png", True
 For intScroll = 0 To intScrolls
  If Environment.Value("Browser") = "CHROME" Then
   strScrollPos = "scrollY"
  Else
   strScrollPos = "document.documentElement.scrollTop"
  End If
  If pgApp.RunScript("document.documentElement.scrollHeight - " & strScrollPos) > pgApp.RunScript("screen.height") Then  
   intY = pgApp.RunScript(strScrollPos & " + screen.height - 168;")
   pgApp.RunScript "window.scrollTo(0, " & intY & ");"
   Wait 1  
   Browser("").CaptureBitmap "screenshot" & (intScroll + 1) & ".png", True
  End If          
 Next
 
 'To merge the images to generate full page screenshot
 Call MergeImages
End Function

'########################################################################################
'This is to merge all individual images to one full page screenshot
'########################################################################################
Function MergeImages   
    Dim drawImage, grapImage, imgFormat, imgLayer, imgPT
    Set drawImage = DotNetFactory.CreateInstance("System.Drawing.Bitmap", "System.Drawing", 1920, 1050)
    drawImage.SetResolution 50, 45
    Set grapImage = DotNetFactory.CreateInstance("System.Drawing.Graphics").FromImage(drawImage)
   
    Set imgLayer = DotNetFactory.CreateInstance("System.Drawing.Bitmap", "System.Drawing", "C:\screenshot0.png")
    Set imgPT = DotNetFactory.CreateInstance("System.Drawing.Point", "System.Drawing", 0, 0)
    grapImage.DrawImage Layer1, pt1
   
    Set imgLayer = DotNetFactory.CreateInstance("System.Drawing.Bitmap", "System.Drawing", "C:\screenshot1.png")
    Set imgPT = DotNetFactory.CreateInstance("System.Drawing.Point", "System.Drawing", 0, 540)
    grapImage.DrawImageUnScaled Layer2, pt2
   
    Set imgFormat = DotNetFactory.CreateInstance("System.Drawing.Imaging.ImageFormat", "System.Drawing", Nothing)
    drawImage.Save "finalScreenshot.png", format.PNG
End Function


This code is for UFT/VBScript and you can use the same logic by applying different APIs available for SELENIUM or any other tools.

Comments

  1. Your info is really amazing with impressive content..Excellent blog with informative concept. Really I feel happy to see this useful blog, Thanks for sharing such a nice blog..
    If you are looking for any Data science Related information please visit our website best course for data science page!

    ReplyDelete
  2. Thanks for sharing this wonderful content.its very useful to us.
    I gained many unknown information, the way you have clearly explained is really fantastic.This is incredible,I feel really happy to have seen your webpage and look forward to somany more entertaining times reading here.
    oracle training in chennai

    oracle training institute in chennai

    oracle training in bangalore

    oracle training in hyderabad

    oracle training

    hadoop training in chennai

    hadoop training in bangalore




    ReplyDelete
  3. Uft - Take Full Page Screenshot By Scrolling The Page >>>>> Download Now

    >>>>> Download Full

    Uft - Take Full Page Screenshot By Scrolling The Page >>>>> Download LINK

    >>>>> Download Now

    Uft - Take Full Page Screenshot By Scrolling The Page >>>>> Download Full

    >>>>> Download LINK aD

    ReplyDelete
  4. this code works well for scrolling and taking screenshots however I am getting an error in the merge function for the line "grapImage.DrawImage Layer1, pt1"
    the error is external object System.Drawing.Graphics: DrawImage has thrown the following exception Ambiguous match found

    also the merge function only works if you have screenshot0 and screenshots1 (two scrolls) seems to me this function needs to have a for loop in case you have more than 2 screenshots

    ReplyDelete

Post a Comment

Popular posts from this blog

Some good Resources / Blogs / Sites for Selenium Users

Here I have listed out some good blogs and sites by extensive selenium automation users. Hope these will help you a lot. http://automationtricks.blogspot.com  - by NirajKumar http://www.theautomatedtester.co.uk/ http://testerinyou.blogspot.com   - by Naga/Mathu http://seleniumready.blogspot.com  - by Farheen Khan http://seleniumdeal.blogspot.com/  - Amit Vibhuti http://seleniumexamples.com/blog Sauce Labs and BrowserMob are companies doing cloud and extensive selenium automation services, products, etc http://saucelabs.com/blog http://blog.browsermob.com http://testingbot.com/ Cedric Beust -  creator of the TestNG Java testing framework. http://beust.com/weblog/ http://blog.reallysimplethoughts.com/  - by Samit Badle, Created many Selenium IDE Plug-Ins Available Colud Testing: 1. SauceLabs 2. Soasta 3. BrowserMob 4. CloudTesting.com  etc. Selenium Testing Products: 1. Twist by ThoughtWorks 2.  TestMaker by  PushToTest 3. Element34 company providi

Change IE Browser ZOOM settings

Lot of UI automation testers could have faced this problem as we could change the zoom settings while operating manually for our convenience and forgot to reset to 100%. But our QTP and some other related tools would operate the browser perfectly if browser zoom is 100%. So wee need to change the zoom before start to run the scripts. Its better to have a code snippet in our framework to change this zoom setting right? Here we go... 1. We can simply change the Registry values before Invoking IE Function  ChangeRegistry   Dim  objShell   Set  objShell =  CreateObject ( "WScript.Shell" )  objShell.RegWrite  "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Zoom\ZoomFactor" ,  "100000" ,  "REG_DWORD"   Set  objShell =  Nothing End   Function This option is very useful. But in real time, lot of customers could have restricted write access to windows registry. So we can try other options. 2. Use IE COM object and Change