网页链接 - http://newtours.demoaut.com/mercurywelcome.php 脚步 - 1.首先访问链接(需要登录此页面,因为您必须通过键入一些信息来注册它(不一定它应该是真正的)。 2.我想通过选择单选按钮选择单程旅行而不是往返旅行 - 对于这整个过程,我写了下面的代码 - 但我无法使用以下代码检查第二个单选按钮
Sub tour()
Dim url As String
Dim ie, inpt, a1, a2, a3, a4, a5, rd1, passenger As Object
Set ie = CreateObject("internetexplorer.application")
ie.Visible = True
url = "http://newtours.demoaut.com/mercurywelcome.php"
ie.navigate url
While ie.readystate <> 4
DoEvents
Wend
MsgBox "plz set username and password in this code/"
Set inpt = ie.document.getelementsbytagname("input")
For Each a1 In inpt
If a1.getattribute("name") = "userName" Then
a1.Value = "*****"
Exit For
End If
Next
For Each a2 In inpt
If a2.getattribute("name") = "password" Then
a2.Value = "*****"
Exit For
End If
Next
For Each a3 In inpt
If a3.getattribute("name") = "login" Then
a3.Click
Exit For
End If
Next
Do
If ie.readystate = 4 Then
Exit Do
Else
DoEvents
End If
Loop
'*******facing issue in below code
Set rd1 = ie.document.getelementsbyname("tripType")
For Each a4 In rd1
If a4.getattribute("value") = "oneway" Then
a4.Click
'*************
Exit For
End If
Next
'Set passenger = ie.document.getelementsbytagname("select")
'For Each a5 In passenger
'If a5.getattribute("name") = "passCount" Then
'a5.Value = 3
'Exit For
'End If
'Next
End Sub
答案 0 :(得分:0)
这是选择&#34;单向&#34;的最直接方式。单选按钮
ie.document.all.Item("tripType")(1).Checked = True
如果您更改
,您的方法也会有效 a4.Click
到
a4.Checked = True