如何使用VBA填写HTML自动填充字段? [英] How to fill in html autocomplete fields using vba?

查看:108
本文介绍了如何使用VBA填写HTML自动填充字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个将数据输入到在线计算器中并获得计算结果的宏

I am writing a macro that enter data into a online calculator and get the computed results

链接: https://www.icao.int/environmental-protection/CarbonOffset/Pages/default.aspx

我正在尝试在网站中填写来自城市/机场"的值.

I am trying to fill the values of "from city/airport" in the website.

这是我的代码:

Sub get_CO2()
 Dim ie As Object
  Set ie = New InternetExplorerMedium
  ie.Navigate "https://applications.icao.int/icec"
  Do While ie.ReadyState <> 4: DoEvents: Loop
  ie.Visible = True
  With ie.Document
      .getElementById("passengerNo").Value = 7
      .getElementById("select1").selectedIndex = 1
      .getElementById("select2").selectedIndex = 1
      ' .getElementByName("frm1").Value = "XXX"
      ' .getElementByName("to1").Value = "XXX"
      .getElementById("computeByInput").Click
   End With
End Sub 

这是行不通的.它显示对象不支持此属性或方法"我该如何填写这种类型?我可以使用什么功能?如果不知道机场代码,是否仍然可以输入国家名称,然后选择出现的第一个选项?

It is doesnt work. It shows "object do not support this property or method" How can i fill in this kind of types? What function can i use? If the airport code is not known, is there anyway to enter the name of the country and just pick to first option showing up?

推荐答案

我已经知道如何使用vba做到这一点.要求完整的代码

I have figured out how to do this with vba. complete code requested

iedoc.getElementsByName("frm1")(0).innerText = "somecountry"            ' enter string of country
Set li_arr = iedoc.getElementById("ui-id-1").getElementsByTagName("li")
Do While li_arr.Length = 0: DoEvents: Loop     ' wait for the drop down menu to come up
li_arr(0).Click                                ' now click the first option

这篇关于如何使用VBA填写HTML自动填充字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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