Home > Blockchain >  Element Out Of The ScreenShot error while taking screenshot from whatsapp using selenium and VBA
Element Out Of The ScreenShot error while taking screenshot from whatsapp using selenium and VBA

Time:07-17

I need somebody to help with selenium classes to bring the information about message read/receipt to the excel sheet. From the help in my previous question, I have got somewhere. But I need more help for going further.

I send message from excel sheet, easily. But cannot bring the read receipt data back to excel sheet I have a code like below

Sub iselementpresenttest()
    
Dim bot As New WebDriver
Dim ks As New Keys

'Init New Chrome instance & navigate to WebWhatsApp
bot.Start "chrome", "https://web.whatsapp.com/"
bot.Get "/"
bot.Window.Maximize
MsgBox "Please scan the QR code. After you are logged in, please confirm this message box by clicking 'ok'"
bot.Wait (3500)
        

       bot.FindElementByXPath("//span[@data-testid='status-dblcheck']").TakeScreenshot.Copy
       Sheets(1).Cells(5, 5).Paste

        
    End Sub

It gives me error Element Out Of The ScreenShot.

HTML:

<span data-testid="status-dblcheck" data-icon="status-dblcheck" ><svg viewBox="0 0 18 18" width="18" height="18" ><path fill="currentColor" d="m17.394 5.035-.57-.444a.434.434 0 0 0-.609.076l-6.39 8.198a.38.38 0 0 1-.577.039l-.427-.388a.381.381 0 0 0-.578.038l-.451.576a.497.497 0 0 0 .043.645l1.575 1.51a.38.38 0 0 0 .577-.039l7.483-9.602a.436.436 0 0 0-.076-.609zm-4.892 0-.57-.444a.434.434 0 0 0-.609.076l-6.39 8.198a.38.38 0 0 1-.577.039l-2.614-2.556a.435.435 0 0 0-.614.007l-.505.516a.435.435 0 0 0 .007.614l3.887 3.8a.38.38 0 0 0 .577-.039l7.483-9.602a.435.435 0 0 0-.075-.609z"></path></svg></span>

CodePudding user response:

As you are seeing Element Out Of The ScreenShot error presumably you may need to scroll the element within the Viewport before taking the screenshot as follows:

Set element = bot.FindElementByXPath("//span[@data-testid='status-dblcheck']")
element.ScrollIntoView().TakeScreenshot().Copy
Sheets(1).Cells(5, 5).PasteSpecial
  • Related