硒VBA:driver.captureEntirePageScreenshot.Copy

问题描述:

新的论坛,和新的Selenium VBA。提前为我的无知道歉。 但是我已经搜索过任何VBA版本,它可以捕获整个页面元素而无需插件或使用Java。硒VBA:driver.captureEntirePageScreenshot.Copy

我想保持这个尽可能简单,以捕获一个完整的页面截图,然后将其从剪贴板粘贴到Excel中的工作表。

代码我到目前为止我了解它可以改进,其中一些可能是不必要的,但我不知道为什么bot.TakeScreenshot.Copy没有工作但只捕获可见屏幕时为什么不起作用。

Public Sub CommandButton1_Click() 

Dim bot As New WebDriver, rng As Range 
Set rng = Range(Worksheets("sheet1").Range("A2"), 
Worksheets("sheet1").Range("A2").End(xlDown)) 

'this loops through each href in cells navigating to the page unless the cell has end in it 

For Each cell In rng 
TextBox2.Text = ActiveCell.Text 
TextBox3.Text = ActiveCell(1, 2).Text 
If ActiveCell.Text = "End" Then 
bot.Quit 
Else 
bot.Start "chrome", TextBox2.Text 
bot.Window.Maximize 
bot.Get "/" 

'this takes a screenshot of each url in the loop and copys it 

bot.captureEntirePageScreenshot.Copy 

'bot.TakeScreenshot.Copy 

'this creates a new sheet names it according the relavent test related to the url and pastes it in that newlt created sheet 

ActiveWorkbook.Sheets.Add.Name = ActiveCell(1, 2).Text 
ActiveSheet.PasteSpecial 

'this goes back to the original sheet to continue with loop 

Worksheets("sheet1").Select 
ActiveCell.Offset(1, 0).Select 

bot.Quit 
End If 
Next 

End Sub 
+0

这是驱动程序的限制,你不能做这种事, –

+0

感谢@TarunLalwani提出了VBA任何分辨率?我看到了Java备用选项。 – Rich21Kong

+1

将我指向Java替代版本 –

使用模拟浏览器

这是从WIN7机器上自带的硒

示例代码... C线:\用户\ XXXX \应用程序数据\本地\ SeleniumBasic \实例\ VBScript中

Option Explicit 

Sub demoPhantomJSDriver() 

    Dim aaa As Selenium.PhantomJSDriver 
    Set aaa = New Selenium.PhantomJSDriver 
    aaa.Get "https://*.com/questions/tagged/vba?sort=newest&pageSize=50" 
    aaa.Window.Maximize 

    Dim bbb As Object 
    Set bbb = aaa.TakeScreenshot 
    bbb.ToExcel Range("h3") 
    Set bbb = Nothing 

End Sub