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 attributename
:
<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
Null
results). TheNavigate
method returns immediately, so you have to wait for the page to finish loading:Do WScript.Sleep 100LoopUntil IE.ReadyState = 4
inputs
contains aDispHTMLElementCollection
, not a string, so trying to display it with aMsgBox
will 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'outerHtml
property:ForEach 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:
ForEach 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 100LoopUntil ie.ReadyState = 4'get the content of the iframeSet iframe = ie.document.getElementsByTagName("iframe")(0).contentWindow
'get the jobId input element inside the iframeForEach jobId In iframe.document.getElementsByName("jobId")
MsgBox jobId.value, 64, "Job ID"Next
Post a Comment for "Get Element By Tag Name"