vb无法点击下拉菜单并选择网站上的值 - 网页抓取

时间:2015-10-08 15:44:50

标签: excel-vba vba excel

我正试图从网站上提取一些数据。我想点击网站上的下拉按钮"选择付款频率"并选择" YEARLY"从中。但是,我无法选择它。我尝试了所有组合,但我无法做到。请在下面找到我正在使用的代码。

Sub PC()
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
ie.Top = 0
ie.Left = 0
ie.Width = 800
ie.Height = 600
ie.Visible = True
ie.Navigate (http://www.iciciprulife.com/public/Cash_Advantage/buy-Cash-Advantage-online.htm?UID=497)

Application.Wait (Now + TimeValue("0:00:01"))
Do While ie.Busy
DoEvents
Loop
ie.document.getElementById("datepicker2").Value = “12/10/1997”
ie.document.getElementById("imobile").Value = "9987587821"
ie.document.getElementById("iEmail").Value = "jainsweta29@gmail.com"
ie.document.getElementById("closebalfund").Click
Application.Wait (Now + TimeValue("0:00:01"))
While ie.Busy
DoEvents
Wend
ie.document.getElementById("premium").Value = "24000"
ie.document.getElementById("paymentFrequency").Value = "YEARLY"
While ie.Busy
DoEvents
Wend
End Sub

1 个答案:

答案 0 :(得分:0)

通过文本设置组合的值(即.Value="YEARLY")会失败,因为它必须区分大小写,对您看不到的空格字符敏感等等...

从组合中选择更安全的方法是使用您要选择的项目的索引(位置)。在该组合中,它位于第3位,因此索引为2,基于零的索引。你可以试试这个:

ie.document.getElementById("paymentFrequency").SelectedIndex = 2

我在你的代码中怀疑的另一件事是我没看到变量Premium定义在哪里。我猜它必须定义为整数,某处。

相关问题