Get Element By Tag Name
Solution 1:
You're using getElementsByName when you actually mean to use getElementsByTagName. The former returns elements based on the value of their attribute name:
<input name="videoUrl" ...>
whereas the latter returns elements based on the name of the tag:
<input name="videoUrl" ...>
Edit: Two other things I noticed:
You don't seem to wait for IE to finish loading the page (which might explain why you're getting
Nullresults). TheNavigatemethod returns immediately, so you have to wait for the page to finish loading:Do WScript.Sleep 100 Loop Until IE.ReadyState = 4inputscontains aDispHTMLElementCollection, not a string, so trying to display it with aMsgBoxwill give you a type error. Same goes for the members of the collection. If you want to display the tags in string form use the objects'outerHtmlproperty:For Each Z In inputs MsgBox "Item = " & Z.outerHtml, 64, "input" Next
Edit2: To get just the value of the attribute value of elements whose name attribute has the value jobId you could use this:
For Each jobId In IE.document.getElementsByName("jobId")
WScript.Echo jobId.value
Next
Edit3: The page you're trying to process contains an iframe (sorry, I failed to notice that earlier). This is what prevents your code from working. Element getter methods like getElementsByName or getElementsByTagName don't work across frame boundaries, so you need to run those methods on the content of the iframe. This should work:
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate "http://..."
Do
WScript.Sleep 100
Loop Until ie.ReadyState = 4
'get the content of the iframe
Set iframe = ie.document.getElementsByTagName("iframe")(0).contentWindow
'get the jobId input element inside the iframe
For Each jobId In iframe.document.getElementsByName("jobId")
MsgBox jobId.value, 64, "Job ID"
Next
Post a Comment for "Get Element By Tag Name"