Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用excelvba在Chrome中注入Javascript_Javascript_Vba_Google Chrome_Excel - Fatal编程技术网

用excelvba在Chrome中注入Javascript

用excelvba在Chrome中注入Javascript,javascript,vba,google-chrome,excel,Javascript,Vba,Google Chrome,Excel,我正在尝试使用VBA将搜索条件、登录或其他内容注入Chrome窗口。在IE中,这个练习并不困难,因为IE是DOM中的顶级对象。在VBA中使用shell函数完全搞不清顶部的文档对象模型是什么样的,以访问打开的窗口。下面是我的示例代码 Function sparkroomInChrome() Dim chromePath As String chromePath = """C:\Program Files (x86)\Google\Chrome\Application\chrome.ex

我正在尝试使用VBA将搜索条件、登录或其他内容注入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

对于这方面的任何指导或对其他类似解决方案的任何见解,我们将不胜感激。谢谢。

使用Selenium VBA完成您的任务

1) 下载并安装“Selenium包装器库”最新版本->站点:

2) 打开Excel-转到VBA中的“工具->参考..”

3) 在参考中选择“Selenium类型库”

4) 尝试下面的示例代码

Public Sub Search_4_Cat()

  Dim selenium As New Selenium.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

有关更多详细信息,请检查:

我没有这方面的经验,但是您在
Shell
命令中缺少一个结束引号和一个右括号。不确定这是否是复制/粘贴错误。不像IE Chrome没有COM自动化接口,你不能从VBA与它的DOM交互。那怎么办?在上。您可以从以下站点选中“Selenium VBA”选项::Selenium VBA是一个使用流行的Selenium web测试工具的Windows COM库。它使使用Excel和VBA代码或通过双击执行的简单VBS文件实现web浏览自动化成为可能。可以使用名为“Selenium IDE”的Firefox插件记录用户的操作,并使用提供的格式化程序将其转换为VBA或VBS。我支持@dee,您应该使用Selenium。我通常使用PhantomJS浏览器和Selenium来保持它的不可见和干净。