用vba和chrome填写表格 [英] fill out form using vba and chrome

查看:572
本文介绍了用vba和chrome填写表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我可以使用IE来完成这项工作。

  Dim ie As InternetExplorer 
Set ie = New InternetExplorer
ie.Navigatewww.google.com
ie.document.getElementByID(blah)。value =blah

我好奇是否有一种方法可以导航到网站,并使用除IE之外的其他IE浏览器,例如FireFox或Chrome来填写信息。



<我知道如何使用任何浏览器导航到其他网站,例如Chrome浏览器,但是我想知道如何使用Chrome浏览器填写www.google.com上的搜索字段。


$

 调用Shell(C:\ Program Files \Google\Chrome\Application\chrome.exe&&URL )


解决方案

您可以使用 Selenium wrapper 来驱动Chrome或Firefox(或PhantomJS)。请注意,它目前处于测试阶段。一旦安装完成,可以添加一个SeleniumWrapper类型库的引用或者使用后期绑定(下面的例子)。

在我的(非常)有限的测试中,唯一明显的区别是加载驱动程序需要几秒钟。

以上是一个简单的例子(修改为使用后期绑定),它填充了Google中的搜索字段,点击搜索按钮:

pre $ Dim selDriver As Object
Set selDriver = CreateObject(SeleniumWrapper.WebDriver)

selDriver.Startchrome,http://www.google.com/
selDriver.Openhttp://www.google.com
selDriver.Type name = q,Eiffel Tower
selDriver.Clickname = btnG

selDriver.stop


currently i can accomplish this using IE

Dim ie As InternetExplorer
Set ie = New InternetExplorer
ie.Navigate "www.google.com"
ie.document.getElementByID("blah").value = "blah"

im curious if there is a way to navigate to website and fill out info using other than IE with VBA for example with FireFox or Chrome

i know how to navigate to other websites using any of the explorers for example Chrome as per below, but i would like to know how can fill out fields like search field on www.google.com using Chrome

call Shell("C:\Program Files\Google\Chrome\Application\chrome.exe"& " " & URL)

解决方案

You can use this Selenium wrapper to drive Chrome or Firefox (or PhantomJS). Note that it is currently in beta. Once it is installed, either add a reference to SeleniumWrapper Type Library or use late binding (example below).

In my (very) limited tests, the only noticeable difference is the couple seconds it takes to load the driver.

Here is a simple example from the link above (modified to use late binding) that fills out the search field in Google and clicks the search button:

Dim selDriver As Object
Set selDriver = CreateObject("SeleniumWrapper.WebDriver")

selDriver.Start "chrome", "http://www.google.com/"
selDriver.Open "http://www.google.com"
selDriver.Type "name=q", "Eiffel Tower"
selDriver.Click "name=btnG"

selDriver.stop

这篇关于用vba和chrome填写表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆