使用Excel VBA在Chrome浏览器中进行Javascript注入

我正在尝试使用VBA将search条件或login或其他任何内容插入到Chrome窗口中。 在IE中,这个练习并不困难,因为IE是DOM中的顶级对象。 完全混淆在VBA中使用shell函数什么文档对象模型看起来像在顶部访问打开的窗口。 这是我的示例代码

Function sparkroomInChrome() Dim chromePath As String chromePath = """C:\Program Files (x86)\Google\Chrome\Application\chrome.exe""" Shell (chromePath & " -url https://google.com End Function Function userCredentials() document.getElementsByClassName("gsfi")[0].value = "cats"; End Function 

任何指导将超级赞赏这个或其他类似的解决scheme的任何洞察力。 谢谢。

使用Selenium VBA来完成您的任务。

1)下载并安装“SeleniumWarpper Library”最新版本 – >网站: https : //code.google.com/p/selenium-vba/

2)打开Excel – 进入“工具 – >参考..”在VBA中

3)select“SeleniumWrappertypes库” – 参考文献

在这里输入图像说明

4)尝试下面的示例代码。

 Public Sub Search_4_Cat() Dim selenium As New SeleniumWrapper.WebDriver selenium.Start "chrome", "https://www.google.com/", False selenium.Open "https://www.google.com/" selenium.Type "name=q", "Cat" selenium.Click "name=btnG" 'selenium.stop ' this will close the browser End Sub 

有关更多详细信息,请查看: https : //code.google.com/p/selenium-vba/