Selenium VBA:driver.captureEntirePageScreenshot.Copy

新的论坛,和新的Selenium VBA。 对我的无知事先道歉。 不过,我已经search了任何这个VBA版本,它捕获整个页面元素没有插件或使用Java。

我想保持这个尽可能简单,以捕获一个完整的页面截图,然后从剪贴板粘贴到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 

使用无头浏览器

这是从selenium自带的示例代码

在win7机器上… C:\ Users \ xxxx \ AppData \ Local \ SeleniumBasic \ Examples \ VBScript

 Option Explicit Sub demoPhantomJSDriver() Dim aaa As Selenium.PhantomJSDriver Set aaa = New Selenium.PhantomJSDriver aaa.Get "https://stackoverflow.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