Discussion:
innerTEXT
(too old to reply)
g***@pnmac.com
2018-04-19 17:41:54 UTC
Permalink
Hi. Trying to display the innertext of the 3 SPAN classes, but I am getting error message. My eventual goal is to write a line of code to SELECT the value "servicing executive dashboard". My .vbs code is:

wscript.echo oIE.Document.getElementById("RefreshReportName-selectized").getElementsByTagName("span")(1).innerText

Website code is as follows:

<form class="uk-form-horizontal">

<div class="uk-margin">

<label class="uk-form-label" for="rptNameArch">Report Name</label>

<div class="uk-form-controls">

<select tabindex="-1" class="selectized" id="RefreshReportName" style="display: none;">
<option selected="selected" value=""></option></select>

<div class="selectize-control single">
<div class="selectize-input items has-options not-full">

<input tabindex="-32768" id="RefreshReportName-selectized" style="left: 0px; width: 148.21px; position: relative; opacity: 1;" type="text"
placeholder="Select Report to Archive" autocomplete="off">
</div>

<div class="selectize-dropdown single" style="left: 0px; top: 40px; width: 749.75px; display: none; visibility: visible;">
<div class="selectize-dropdown-content">
<div class="option selected" data-selectable="" data-value="20291">

<span class="highlight">Servicing</span>
<span class="highlight">Executive</span>
<span class="highlight">Dashboard</span>
</div></div></div></div>

Can someone tell me what I am doing wrong?

Thanks
Evertjan.
2018-04-19 21:16:37 UTC
Permalink
Post by g***@pnmac.com
Hi. Trying to display the innertext of the 3 SPAN classes, but I am
getting error message. My eventual goal is to write a line of code to
wscript.echo
oIE.Document.getElementById("RefreshReportName-selectized").getElementsBy
TagName("span")(1).innerText
The <input> you are referring to with your getElementById,
like all <input>'s,
does not have any child tags,
and <input> can never, imho, have child tags.

You will have to specify the <form> id or a <div> id.
Post by g***@pnmac.com
<form class="uk-form-horizontal">
<div class="uk-margin">
<label class="uk-form-label" for="rptNameArch">Report Name</label>
<div class="uk-form-controls">
<select tabindex="-1" class="selectized" id="RefreshReportName"
style="display: none;"> <option selected="selected"
value=""></option></select>
<div class="selectize-control single">
<div class="selectize-input items has-options not-full">
0px; width: 148.21px; position: relative; opacity: 1;" type="text"
placeholder="Select Report to Archive" autocomplete="off"> </div>
<div class="selectize-dropdown single" style="left: 0px; top: 40px;
width: 749.75px; display: none; visibility: visible;"> <div
class="selectize-dropdown-content"> <div class="option selected"
data-selectable="" data-value="20291">
<span class="highlight">Servicing</span>
<span class="highlight">Executive</span>
<span class="highlight">Dashboard</span>
</div></div></div></div>
Can someone tell me what I am doing wrong?
Thanks
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mayayana
2018-04-19 22:23:20 UTC
Permalink
<***@pnmac.com> wrote

| wscript.echo
oIE.Document.getElementById("RefreshReportName-selectized").getElementsByTagName("span")(1).innerText
|

I assume this is your webpage. Why not just
assign an ID? This works for me.....

<HTML><HEAD></HEAD>
<BODY>
<span ID="span1" class="highlight">Servicing</span>
<span class="highlight">Executive</span>
<span class="highlight">Dashboard</span>
</BODY></HTML>


Loading the webpage in IE I then call a script
like so:

Set shl = CreateObject("Shell.Application")
Set wins = shl.windows

For i = 0 to wins.count - 1
s = wins.item(i).LocationURL
If InStr(s, "test1") > 0 Then
Set doc = wins.item(i).document
MsgBox doc.all("span1").innerText
Set doc = Nothing
End If
Next
Set wins = Nothing
Set shl = Nothing


You may know this, but later versions of IE
can be tricky. If you specify standards doctype
you get a different DOM than if you go with
"quirks mode".
g***@pnmac.com
2018-04-20 12:51:48 UTC
Permalink
Post by g***@pnmac.com
wscript.echo oIE.Document.getElementById("RefreshReportName-selectized").getElementsByTagName("span")(1).innerText
<form class="uk-form-horizontal">
<div class="uk-margin">
<label class="uk-form-label" for="rptNameArch">Report Name</label>
<div class="uk-form-controls">
<select tabindex="-1" class="selectized" id="RefreshReportName" style="display: none;">
<option selected="selected" value=""></option></select>
<div class="selectize-control single">
<div class="selectize-input items has-options not-full">
<input tabindex="-32768" id="RefreshReportName-selectized" style="left: 0px; width: 148.21px; position: relative; opacity: 1;" type="text"
placeholder="Select Report to Archive" autocomplete="off">
</div>
<div class="selectize-dropdown single" style="left: 0px; top: 40px; width: 749.75px; display: none; visibility: visible;">
<div class="selectize-dropdown-content">
<div class="option selected" data-selectable="" data-value="20291">
<span class="highlight">Servicing</span>
<span class="highlight">Executive</span>
<span class="highlight">Dashboard</span>
</div></div></div></div>
Can someone tell me what I am doing wrong?
Thanks
hi. decided to go with the following instead.. but now I just need to click on the value.. nothing is happening. the echo works fine though..
Set oElementCollection = oIE.Document.getElementsByClassName("option selected")
For Each span In oElementCollection
wscript.echo span.parentNode.innerText
span.parentNode.Click
Next
Mayayana
2018-04-20 13:01:54 UTC
Permalink
<***@pnmac.com> wrote

| span.parentNode.Click

It looks like you're getting back into your
Selectize library with that one. So won't you have
to reference that object? And can you do that
with VBS? Have you considered dropping all that
complication and just using straight script? Your
other option would be to just use script to do
whatever the click is supposed to do.
JJ
2018-04-20 13:08:23 UTC
Permalink
Post by g***@pnmac.com
hi. decided to go with the following instead.. but now I just need to
click on the value.. nothing is happening. the echo works fine though..
Set oElementCollection = oIE.Document.getElementsByClassName("option selected")
For Each span In oElementCollection
wscript.echo span.parentNode.innerText
span.parentNode.Click
Next
You're selecting the wrong element.

You're selecting this element:

<div class="option selected" data-selectable="" data-value="20291">

Then you clicked the parent node of the selected element, which is:

<div class="selectize-dropdown-content">

So, that's not the SPAN element.

You should use `children` instead of `parentNode`. i.e.

Set oElementCollection = oIE.Document.getElementsByClassName("option selected")
For Each span In oElementCollection(0).children
wscript.echo span.innerText
span.Click
Next
JJ
2018-04-20 12:54:42 UTC
Permalink
Post by g***@pnmac.com
wscript.echo oIE.Document.getElementById("RefreshReportName-selectized").getElementsByTagName("span")(1).innerText
[snip]

You're selecting the SPAN elements from the wrong parent element. The SPAN
elements are not contained within the element whose ID is
`RefreshReportName-selectized`. They're children of a DIV element.

I'd suggest you use the SELECT element as the starting point element, since
it has an ID. Then from that element, get the next element sibling (which is
a DIV element), then use that DIV element as the parent element to get the
SPAN elements. e.g.

'get the SELECT element
ele = oIE.Document.getElementById("RefreshReportName")
'get the DIV element
ele = ele.nextElementSibling
'get the SPAN elements
eles = ele.getElementsByTagName("span")

wscript.echo eles(1).innerText
g***@pnmac.com
2018-04-20 14:15:32 UTC
Permalink
Post by g***@pnmac.com
wscript.echo oIE.Document.getElementById("RefreshReportName-selectized").getElementsByTagName("span")(1).innerText
<form class="uk-form-horizontal">
<div class="uk-margin">
<label class="uk-form-label" for="rptNameArch">Report Name</label>
<div class="uk-form-controls">
<select tabindex="-1" class="selectized" id="RefreshReportName" style="display: none;">
<option selected="selected" value=""></option></select>
<div class="selectize-control single">
<div class="selectize-input items has-options not-full">
<input tabindex="-32768" id="RefreshReportName-selectized" style="left: 0px; width: 148.21px; position: relative; opacity: 1;" type="text"
placeholder="Select Report to Archive" autocomplete="off">
</div>
<div class="selectize-dropdown single" style="left: 0px; top: 40px; width: 749.75px; display: none; visibility: visible;">
<div class="selectize-dropdown-content">
<div class="option selected" data-selectable="" data-value="20291">
<span class="highlight">Servicing</span>
<span class="highlight">Executive</span>
<span class="highlight">Dashboard</span>
</div></div></div></div>
Can someone tell me what I am doing wrong?
Thanks
that actually worked for a minute.. but after the first time it worked I am getting an object required error [undefined]. I am using:

'---------------------------------------------------------------
'WORKS WITH SELECTIZED DROPDOWNS!!!!!!!!!!!
Set oElementCollection2 = oIE.Document.getElementsByClassName("option selected")
For Each span In oElementCollection2(0).children
wscript.echo "child: " + span.innerText
'span.Click
Next
'---------------------------------------------------------------



What am i doing wrong? I was so excited when it worked the first time...
g***@pnmac.com
2018-04-20 15:03:11 UTC
Permalink
Post by g***@pnmac.com
Post by g***@pnmac.com
wscript.echo oIE.Document.getElementById("RefreshReportName-selectized").getElementsByTagName("span")(1).innerText
<form class="uk-form-horizontal">
<div class="uk-margin">
<label class="uk-form-label" for="rptNameArch">Report Name</label>
<div class="uk-form-controls">
<select tabindex="-1" class="selectized" id="RefreshReportName" style="display: none;">
<option selected="selected" value=""></option></select>
<div class="selectize-control single">
<div class="selectize-input items has-options not-full">
<input tabindex="-32768" id="RefreshReportName-selectized" style="left: 0px; width: 148.21px; position: relative; opacity: 1;" type="text"
placeholder="Select Report to Archive" autocomplete="off">
</div>
<div class="selectize-dropdown single" style="left: 0px; top: 40px; width: 749.75px; display: none; visibility: visible;">
<div class="selectize-dropdown-content">
<div class="option selected" data-selectable="" data-value="20291">
<span class="highlight">Servicing</span>
<span class="highlight">Executive</span>
<span class="highlight">Dashboard</span>
</div></div></div></div>
Can someone tell me what I am doing wrong?
Thanks
'---------------------------------------------------------------
'WORKS WITH SELECTIZED DROPDOWNS!!!!!!!!!!!
Set oElementCollection2 = oIE.Document.getElementsByClassName("option selected")
For Each span In oElementCollection2(0).children
wscript.echo "child: " + span.innerText
'span.Click
Next
'---------------------------------------------------------------
What am i doing wrong? I was so excited when it worked the first time...
hi. never mind i figured it out. Thanks so much for the help. Now I don't have to use SendKeys
Continue reading on narkive:
Loading...