VBA에서 적절한 사용자 이름을 입력 할 수 있도록 웹 페이지에서 "사용자 이름"셀에 액세스하려고합니다.
문제는 페이지의 HTML 코드에 "LOGON_USERID"라는 동일한 이름을 가진 요소가 두 개 이상 있고 올바른 요소에 액세스하는 방법을 알 수 없다는 것입니다.
"HTML 코드의 일부"이미지에서 볼 수 있듯이 액세스하려는 줄은 강조 표시된 줄이지 만 그 위에 같은 이름을 가진 다른 요소가 2 개 있습니다.
여러 가지 방법 (다른 방법 또는 변수 유형 등을 사용)을 시도했지만 HTML에 익숙하지 않아 원하는 것을 얻을 수 없습니다.
Sub Pum()
Dim ie As New InternetExplorer
'Dim IEDoc As IHTMLElementCollection
Dim IEDoc As HTMLDocument
Dim name As Object
Dim nameList As HTMLInputElement
Dim WRONGS As DispHTMLElementCollection
Dim Elems As HTMLElementCollection
Dim i As Integer
ie.navigate "thewebsiteinquestion"
ie.Visible = False
WaitIE ie
Set IEDoc = ie.document
'MsgBox IEDoc.DocumentElement.
'Elems = IEDoc.getElementsByTagName("INPUT")
MsgBox TypeName(IEDoc.getElementById("LOGON_USERID").all)
Set Elems = IEDoc.getElementById("LOGON_USERID")
'For i = 0 To 5
MsgBox Elems.Length
'Next i
For Each name In Elems.Children
MsgBox name.nodeName
MsgBox name.Attributes
MsgBox name.all
Next
'If ((NameStr Isnot Nothing And (NameStr.Length <> 0)) Then
'If NameStr = "LOGON_USERID" Then
'If TypeName(IEDoc.all("LOGON_USERID")) = "HTMLInputElement" Then
'MsgBox TypeName(IEDoc.all("LOGON_USERID"))
'Set names = IEDoc.all.Item("text")
'TypeName (InputUsernameTextzone)
'Dim Question As IHTMLElement
'Question = InputUsernameTextzone.parentElement
'MsgBox TypeName(InputUsernameTextzone.parentElement.getAttribute("name"))
'InputUsernameTextzone.parentElement
'CELLULE.value = "qtc2464"
WaitIE ie
Set ie = Nothing
Set IEDoc = Nothing
End Sub
다른 방법을 사용하여 유사한 코드 두 개를 시도했지만 여전히 결과가 없습니다. 저를 도울 수 있기를 바랍니다.
더 많은 정보가 필요하면 알려주세요.
다른 두 개의 입력 요소는 다른 유형 ( 숨겨 짐 )이므로 querySelector
속성과 함께 사용 type=text
하여 원하는 요소를 찾을 수 있습니다.
Dim userid As HTMLInputElement
Set userid = IEDoc.querySelector("input[name='LOGON_USERID'][type='text']")
If Not userid Is Nothing Then
' Continue with user id element
Else
MsgBox "LOGON_USERID not found on the page"
End If
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다