Select 使用 VBScript 的 Internet Explorer 页面下拉列表中的项目
Select item from Dropdown in Internet Explorer page with VBScript
我正在尝试从下拉列表中打开 URL 和 select 值,然后提交表单,但我无法从下拉列表中 select 值。
这是我当前的代码:
Dim vb
Dim ie
Set vb = CreateObject("WScript.Shell")
Set ie = CreateObject("InternetExplorer.Application")
'start IE
ie.Visible = True
ie.Navigate "https://www.nseindia.com/live_market/dynaContent/live_watch/equities_stock_watch.htm"
'Loop until page load
Do While ie.Busy
WScript.Sleep 200
Loop
WScript.Sleep 200
'Activate ie windows
vb.AppActivate ("NSE - National Stock Exchange of India Ltd. - Internet Explorer")
WScript.Sleep 200
'Now i want to select from dropdown, How can i select option from dropdown list.
'Submit the form
ie.Document.All.Item("dataform").Submit
Set vb = Nothing
Set ie = Nothing
通常你会遍历所有选项并select你想要的选项:
For Each objOption In ie.Document.getElementById("bankNiftySelect").Options
With objOption
If .Value = "foSec" Then
.Selected = True
Else
.Selected = False
End If
End With
Next
您也可以尝试使用以下代码:
For Each objOption In IE.Document.getElementById("bankNiftySelect").getElementsByTagName("option")
With objOption
If .Value = "foSec" Then
.Selected = True
Else
.Selected = False
End If
End With
Next
我正在尝试从下拉列表中打开 URL 和 select 值,然后提交表单,但我无法从下拉列表中 select 值。
这是我当前的代码:
Dim vb
Dim ie
Set vb = CreateObject("WScript.Shell")
Set ie = CreateObject("InternetExplorer.Application")
'start IE
ie.Visible = True
ie.Navigate "https://www.nseindia.com/live_market/dynaContent/live_watch/equities_stock_watch.htm"
'Loop until page load
Do While ie.Busy
WScript.Sleep 200
Loop
WScript.Sleep 200
'Activate ie windows
vb.AppActivate ("NSE - National Stock Exchange of India Ltd. - Internet Explorer")
WScript.Sleep 200
'Now i want to select from dropdown, How can i select option from dropdown list.
'Submit the form
ie.Document.All.Item("dataform").Submit
Set vb = Nothing
Set ie = Nothing
通常你会遍历所有选项并select你想要的选项:
For Each objOption In ie.Document.getElementById("bankNiftySelect").Options
With objOption
If .Value = "foSec" Then
.Selected = True
Else
.Selected = False
End If
End With
Next
您也可以尝试使用以下代码:
For Each objOption In IE.Document.getElementById("bankNiftySelect").getElementsByTagName("option")
With objOption
If .Value = "foSec" Then
.Selected = True
Else
.Selected = False
End If
End With
Next