使用 vba 和 chrome 填写表格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13750943/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
fill out form using vba and chrome
提问by live2ride
currently i can accomplish this using IE
目前我可以使用 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
我很好奇是否有办法导航到网站并使用 VBA 以外的 IE 填写信息,例如使用 FireFox 或 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
我知道如何使用任何浏览器导航到其他网站,例如如下所示的 Chrome,但我想知道如何使用 Chrome 填写 www.google.com 上的搜索字段等字段
call Shell("C:\Program Files\Google\Chrome\Application\chrome.exe"& " " & URL)
回答by BenShim
You can use this Selenium wrapperto drive Chrome or Firefox (or PhantomJS). Note that it is currently in beta. Once it is installed, either add a reference to Selenium Type Library or use late binding (example below).
您可以使用此Selenium 包装器来驱动 Chrome 或 Firefox(或 PhantomJS)。请注意,它目前处于测试阶段。安装后,添加对 Selenium 类型库的引用或使用后期绑定(下面的示例)。
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:
这是上面链接中的一个简单示例(修改为使用后期绑定),该示例在 Google 中填写搜索字段并单击搜索按钮:
Dim selDriver As Object
Set selDriver = CreateObject("Selenium.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
回答by Shah
As of 2016, the Selenium wrapper was moved to Github instead of the above Google address. Additionally, if you're using Chrome you'll want to update the web driver for Google Chrome here.
截至 2016 年,Selenium 包装器已移至 Github,而不是上述 Google 地址。此外,如果您使用 Chrome,则需要在此处更新 Google Chrome 的网络驱动程序。
After downloading these items you'll then need to follow the instructions above for adding the library to in your Visual Basic Editor from within Excel. Afer doing so, you should be able fill out a web form using vba and chrome as originally requested.
下载这些项目后,您需要按照上述说明从 Excel 中将库添加到 Visual Basic 编辑器。这样做之后,您应该能够按照最初的要求使用 vba 和 chrome 填写网络表单。