I'm learning about VBA web automation. I have successfully logged in to other websites and pulled data from them, but I couldn't do the same thing for this specific website: https://moodle.telt.unsw.edu.au/.
<html>
<div>
<div>
<div>
<section>
<div>
<div>
<div>
<div>
<iframe>
<html>
<there are more tags under here and if you go far enough you'll reach the elements I want VBA to read. They are under <input> tag>
<div>
I want VBA to get the three login elements that fall under the second <html>
tag that is under <iframe>
: id = "username"
, id ="password"
, and id = "submit"
. I tried getelementbyid("")
but for some reason it couldn't find these elements. I then tried using this code that lists all the elements' tags.
Sub moodleautomation()
Dim IE As Object
Dim website As String
Dim elements As Object
Dim element As Object
Set IE = CreateObject("InternetExplorer.Application")
website = "https://moodle.telt.unsw.edu.au/login/index.php"
With IE
.Visible = True
.Navigate website
Do While .busy Or .ReadyState <> 4
DoEvents
Loop
'get all elements in the document
Set elements = .document.getelementsbytagname("*")
'find how many elements there are in the document
MsgBox elements.Length
'Display each element's tag name
For Each element In elements
MsgBox element.tagName
Next
End With
End Sub
After running this code it shows me the tags until <iframe>
tag then it ignores <html>
tag and all the tags under it and goes directly to div
tag. The problem is that the elements I want to read are inside the second <html>
tag that my code ignored.
Is there a way to read those elements?
EDIT:
Sub moodleautomation()
Dim IE As Object
Dim website As String
Dim elements As Object
Dim element As Object
Set IE = CreateObject("InternetExplorer.Application")
website = "https://moodle.telt.unsw.edu.au/login/index.php"
With IE
.Visible = True
.Navigate website
Do While .busy Or .ReadyState <> 4
DoEvents
Loop
'get iframe elements in the document
Set elements = .document.getelementsbytagname("iframe")
'find how many iframe elements there are in the document
MsgBox elements.Length
'get the iframe document
Set element = elements.contentDocument
End With
End Sub
This code gives me an error message that says "Object doesn't support this property or method" on this line (Set element = elements.contentDocument)