Discussion:
fill in ie form with java
(too old to reply)
smbs
2017-07-09 08:31:29 UTC
Permalink
I am trying to select items from a dropdown menu on a javascript webpage. I want to fill in the menu value via a userform using VB. Relevent Web code source is below

***************************************************************************************
<div class="sa-form-control sa-form-field" style="padding-bottom: 20px;">
<select name="country" class="ui-textfield ui-textfield-system sa-country sa-error-field"><option selected="selected" value="">--Please Select--</option>
<option value="RU">Russian Federation</option>
<option value="US">United States</option>
<option value="ES">Spain</option>
<option value="FR">France</option>
option value="OTHER">Other Country</option>
<option value="">-------- Country &amp; Territories (A-Z) --------</option></select>
<div class="sa-success-icon" style="display: none;"></div><p class="sa-error-tips" style="display: block;">Please select a Country/Region</p></div>
**************************************************************************************************
I have tried the following
oIE.document.getElementsByClassName("ui-textfield ")(0).Value = "RU"
not working
oIE.document.getElementsByName("country")(0).Value = "RU"
Also not working
Any help would be great
Thanx
Dave "Crash" Dummy
2017-07-09 08:57:23 UTC
Permalink
Post by smbs
I am trying to select items from a dropdown menu on a javascript
webpage. I want to fill in the menu value via a userform using VB.
Relevent Web code source is below
***************************************************************************************
20px;"> <select name="country" class="ui-textfield
ui-textfield-system sa-country sa-error-field"><option
selected="selected" value="">--Please Select--</option> <option
value="RU">Russian Federation</option> <option value="US">United
States</option> <option value="ES">Spain</option> <option
value="FR">France</option> option value="OTHER">Other
Country</option> <option value="">-------- Country &amp; Territories
(A-Z) --------</option></select> <div class="sa-success-icon"
block;">Please select a Country/Region</p></div>
**************************************************************************************************
I have tried the following
oIE.document.getElementsByClassName("ui-textfield ")(0).Value = "RU"
not working oIE.document.getElementsByName("country")(0).Value = "RU"
Also not working Any help would be great Thanx
Try it without the "oIE" object:
document.getElementsByName("country")(0).Value = "RU"
--
Crash

"Politics have no relation to morals."
~ Niccolo Machiavelli ~
Ulrich Möller
2017-07-09 13:52:10 UTC
Permalink
Post by smbs
I am trying to select items from a dropdown menu on a javascript webpage. I want to fill in the menu value via a userform using VB. Relevent Web code source is below
***************************************************************************************
<div class="sa-form-control sa-form-field" style="padding-bottom: 20px;">
<select name="country" class="ui-textfield ui-textfield-system sa-country sa-error-field"><option selected="selected" value="">--Please Select--</option>
<option value="RU">Russian Federation</option>
<option value="US">United States</option>
<option value="ES">Spain</option>
<option value="FR">France</option>
option value="OTHER">Other Country</option>
<option value="">-------- Country &amp; Territories (A-Z) --------</option></select>
<div class="sa-success-icon" style="display: none;"></div><p class="sa-error-tips" style="display: block;">Please select a Country/Region</p></div>
**************************************************************************************************
I have tried the following
oIE.document.getElementsByClassName("ui-textfield ")(0).Value = "RU"
not working
oIE.document.getElementsByName("country")(0).Value = "RU"
Also not working
This code should work:
oIE.Document.getElementsByName("country")(0).Value = "RU"
or
oIE.Document.All("country").Value = "RU"

but maybe you have any security issues. In doubt, post a snipped on how
you create and access the IE object.

Ulrich
smbs
2017-07-09 15:02:38 UTC
Permalink
Post by Ulrich Möller
Post by smbs
I am trying to select items from a dropdown menu on a javascript webpage. I want to fill in the menu value via a userform using VB. Relevent Web code source is below
***************************************************************************************
<div class="sa-form-control sa-form-field" style="padding-bottom: 20px;">
<select name="country" class="ui-textfield ui-textfield-system sa-country sa-error-field"><option selected="selected" value="">--Please Select--</option>
<option value="RU">Russian Federation</option>
<option value="US">United States</option>
<option value="ES">Spain</option>
<option value="FR">France</option>
option value="OTHER">Other Country</option>
<option value="">-------- Country &amp; Territories (A-Z) --------</option></select>
<div class="sa-success-icon" style="display: none;"></div><p class="sa-error-tips" style="display: block;">Please select a Country/Region</p></div>
**************************************************************************************************
I have tried the following
oIE.document.getElementsByClassName("ui-textfield ")(0).Value = "RU"
not working
oIE.document.getElementsByName("country")(0).Value = "RU"
Also not working
oIE.Document.getElementsByName("country")(0).Value = "RU"
or
oIE.Document.All("country").Value = "RU"
but maybe you have any security issues. In doubt, post a snipped on how
you create and access the IE object.
Ulrich
Thanx for reply however what you suggested does not work- no security issues as other text blocks are filled in without problems
Ulrich Möller
2017-07-09 16:49:09 UTC
Permalink
Post by smbs
Post by Ulrich Möller
Post by smbs
I am trying to select items from a dropdown menu on a javascript webpage. I want to fill in the menu value via a userform using VB. Relevent Web code source is below
***************************************************************************************
<div class="sa-form-control sa-form-field" style="padding-bottom: 20px;">
<select name="country" class="ui-textfield ui-textfield-system sa-country sa-error-field"><option selected="selected" value="">--Please Select--</option>
<option value="RU">Russian Federation</option>
<option value="US">United States</option>
<option value="ES">Spain</option>
<option value="FR">France</option>
option value="OTHER">Other Country</option>
<option value="">-------- Country &amp; Territories (A-Z) --------</option></select>
<div class="sa-success-icon" style="display: none;"></div><p class="sa-error-tips" style="display: block;">Please select a Country/Region</p></div>
**************************************************************************************************
I have tried the following
oIE.document.getElementsByClassName("ui-textfield ")(0).Value = "RU"
not working
oIE.document.getElementsByName("country")(0).Value = "RU"
Also not working
oIE.Document.getElementsByName("country")(0).Value = "RU"
or
oIE.Document.All("country").Value = "RU"
but maybe you have any security issues. In doubt, post a snipped on how
you create and access the IE object.
Ulrich
Thanx for reply however what you suggested does not work- no security issues as other text blocks are filled in without problems
I have tested both variations with a little test program and it works as
expected. Check for any typo in your element names. You also have the
option to set a break point in your vb code and try to change the value
in the direct window.

Ulrich
JJ
2017-07-09 16:34:15 UTC
Permalink
Post by smbs
I am trying to select items from a dropdown menu on a javascript webpage. I want to fill in the menu value via a userform using VB. Relevent Web code source is below
***************************************************************************************
<div class="sa-form-control sa-form-field" style="padding-bottom: 20px;">
<select name="country" class="ui-textfield ui-textfield-system sa-country sa-error-field"><option selected="selected" value="">--Please Select--</option>
<option value="RU">Russian Federation</option>
<option value="US">United States</option>
<option value="ES">Spain</option>
<option value="FR">France</option>
option value="OTHER">Other Country</option>
<option value="">-------- Country &amp; Territories (A-Z) --------</option></select>
<div class="sa-success-icon" style="display: none;"></div><p class="sa-error-tips" style="display: block;">Please select a Country/Region</p></div>
**************************************************************************************************
I have tried the following
oIE.document.getElementsByClassName("ui-textfield ")(0).Value = "RU"
not working
oIE.document.getElementsByName("country")(0).Value = "RU"
Also not working
Any help would be great
Thanx
Unless you've already made the code to be executed suring the "load" event

Try moving the SCRIPT element after the SELECT element.
Mayayana
2017-07-09 17:46:20 UTC
Permalink
"smbs" <***@gmail.com> wrote

|I am trying to select items from a dropdown menu on a javascript webpage. I
want to fill in the menu value via a userform using VB. Relevent Web code
source is below
|

Are you in the page? If so then either of the
following options will work. You don't need the
inefficiency of "all".

<HTML>
<HEAD>
<SCRIPT LANGUAGE="VBScript">
Sub But1_onclick()
'List1.selectedIndex = 3
List1.value = "FR"
End Sub
</SCRIPT>
</HEAD>
<BODY>

<SELECT ID="List1">
<option value="RU">Russian Federation
<option value="US">United States
<option value="ES">Spain
<option value="FR">France
<option value="OTHER">Other Country
</SELECT>


<INPUT ID="But1" TYPE="button"></input>
</BODY></HTML>

The NAME attribute also seems to work in
place of ID. This is all only in IE, of course. And
with any IE webpage code these days you
need to consider quirks mode vs non-quirks.
Also note that if it's not an HTA then IE11 won't
recognize VBS unless you set compat mode for
the domain. (I'm not sure how that works locally.)

If you're not calling from within the document
context then where are you? In that case you
need to first get the document reference. If it's
not your IE instance then you may not be able
to get at the document object, which would then
require an API call that's not possible from script.
You could try this if necessary:

http://www.jsware.net/jsware/compfiles.php5#jsshl

It's a component for shell functionality. In addition
to things like enumerating windows and getting their
handles, it can return an IE document object from IE,
an HTA, or any other window that has a true IE
browser window in it. The only trick is that IE with tabs
makes finding the desired window more tricky.

Another thing that might be helpful:

http://www.jsware.net/jsware/hxs2chm.php5

That requires a bit of explanation. The IE document
object model is vast. You should really have the help
docs for it. The problem is that the Inet CHM is about
35 MB and CHMs are no longer made available. All
docs are now in the platform SDK, which is a gigantic
package. The help files come as HKS files, for which
there's no standalone reader. It's a pain to just get
basic help files for WSH, IE, etc.

The page above links to an HTA utility you can
use. Download an SDK. (Win7 would probably be
a good choice.) Get out the HXS files, and the utility
will convert them. You'll end up with CHM files covering
all categories of Windows development. The details
to do it are at the link. Once you have an Inet CHM
you can easily look up all details of the IE DOM.

Loading...