Jump to content

ComboBox and IE.au3


Recommended Posts

I want to Copy a value like State/Country, then paste/send it to a web page ComboBox. Is there a command in IE.au3 that does this? Maybe a function similar to ControlCommand even? I looked into _IEAction(), but it doesn't look like it is fit for the task. Maybe I am wrong.

Here is what I was using for the other fields, but it doesn't work for the ComboBoxes:

$state = ClipGet ()
$o_SearchForm = _IEFormGetObjByIndex ($o_IE, 0)
$o_Keywords = _IEFormElementGetObjByIndex ($o_SearchForm, "state")
_IEFormElementSetValue ($o_Keywords, $state)
Link to comment
Share on other sites

I want to Copy a value like State/Country, then paste/send it to a web page ComboBox. Is there a command in IE.au3 that does this? Maybe a function similar to ControlCommand even? I looked into _IEAction(), but it doesn't look like it is fit for the task. Maybe I am wrong.

Here is what I was using for the other fields, but it doesn't work for the ComboBoxes:

$state = ClipGet ()
$o_SearchForm = _IEFormGetObjByIndex ($o_IE, 0)
$o_Keywords = _IEFormElementGetObjByIndex ($o_SearchForm, "state")
_IEFormElementSetValue ($o_Keywords, $state)
you've got the right idea, but have some syntax trouble.

_IEFormElementGetObjByIndex takes a an index number -- did you mean to use _IEFormElementGetObjByName?

I presume that the element is really a SELECT OPTION -- HTML has no ComboBox. Note that the "value" may not be the same as what is displayed -- you need to look at the source.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

you've got the right idea, but have some syntax trouble.

_IEFormElementGetObjByIndex takes a an index number -- did you mean to use _IEFormElementGetObjByName?

I presume that the element is really a SELECT OPTION -- HTML has no ComboBox. Note that the "value" may not be the same as what is displayed -- you need to look at the source.

Dale

Dale, interesting point. I admit I struggle with the IE.au3 syntax, and I may even have more commands than I need. But to clarify what I am doing:

I am copying from a field in an application (i.e Country/State)

$state = ClipGet ()
, and would like to 'paste' that information into a field on a webpage. The field on the webpage is a drop-down list of all the countries in the world.

So all I really need to do is set the value in the web page, which is the drop-down list of all the Countries in the world. If I already have the value stored as a variable (.i.e Canada), how do I set that value to the webpage drop-down list?

Link to comment
Share on other sites

Dale, interesting point. I admit I struggle with the IE.au3 syntax, and I may even have more commands than I need. But to clarify what I am doing:

I am copying from a field in an application (i.e Country/State)

$state = ClipGet ()
, and would like to 'paste' that information into a field on a webpage. The field on the webpage is a drop-down list of all the countries in the world.

So all I really need to do is set the value in the web page, which is the drop-down list of all the Countries in the world. If I already have the value stored as a variable (.i.e Canada), how do I set that value to the webpage drop-down list?

Read this again...

Note that the "value" may not be the same as what is displayed -- you need to look at the source.

You need to look at the HTML source of the web page. Look at the syntax of the SELECT OPTION element for country and hopefully it becomes clear.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Read this again...You need to look at the HTML source of the web page. Look at the syntax of the SELECT OPTION element for country and hopefully it becomes clear.

Note that the "value" may not be the same as what is displayed -- you need to look at the source.

Dale

I am beginning to understand! Beginning...hehe.

Let us assume that that the "value" from $state = ClipGet () is the same as the option I would like to 'Select' from the webpage. For instance, let us assume:

1)$state = ClipGet (), Gives us California

2) That the webpage SELECT option for 'California' exists (identical spelling, not Abbreviation CA).

Then what should my code look like?

With those 2 assumptions being true my code did not work

$state = ClipGet ()
$o_SearchForm = _IEFormGetObjByIndex ($o_IE, 0)
$o_Keywords = _IEFormElementGetObjByIndex ($o_SearchForm, "state")
_IEFormElementSetValue ($o_Keywords, $state)

Results from IE Builder:

Elements for form 0                 
Index   Tag Name    Id  Extra Information   Object Type
6   SELECT  state           DispHTMLSelectElement

Thanks!

Link to comment
Share on other sites

I am beginning to understand! Beginning...hehe.

Let us assume that that the "value" from $state = ClipGet () is the same as the option I would like to 'Select' from the webpage. For instance, let us assume:

1)$state = ClipGet (), Gives us California

2) That the webpage SELECT option for 'California' exists (identical spelling, not Abbreviation CA).

Then what should my code look like?

With those 2 assumptions being true my code did not work

$state = ClipGet ()
$o_SearchForm = _IEFormGetObjByIndex ($o_IE, 0)
$o_Keywords = _IEFormElementGetObjByIndex ($o_SearchForm, "state")
_IEFormElementSetValue ($o_Keywords, $state)

Results from IE Builder:

Elements for form 0                 
Index   Tag Name    Id  Extra Information   Object Type
6   SELECT  state           DispHTMLSelectElement

Thanks!

If you right-click and do a "View Source" on this web page you'll find code like the following (I've edited it way back to just illustrate the point):

<select name='f'>
<option value='sj_home'>Forum Home</option>
<option value='sj_search'>Search</option>
<option value='sj_help'>Help</option>
</select>

You'll note that the entry that shows up in the drop-down on the webpage as "Forum Home" for example actually has a value of 'sj_home' -- that is the value you would set for that element to get "Forum Home" to display. Make sense?

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

If you right-click and do a "View Source" on this web page you'll find code like the following (I've edited it way back to just illustrate the point):

<select name='f'>
<option value='sj_home'>Forum Home</option>
<option value='sj_search'>Search</option>
<option value='sj_help'>Help</option>
</select>

You'll note that the entry that shows up in the drop-down on the webpage as "Forum Home" for example actually has a value of 'sj_home' -- that is the value you would set for that element to get "Forum Home" to display. Make sense?

Dale

OOOOOOOOOOHHHHHHHHH!!!! I understand now!

But, what is the best step now? I have 50 States, and 100's of Countries and need to tell my script to PsuedoCode:

Match $state with "<OPTION value=CA>California</OPTION>"

Then

$state = ClipGet ()
$o_SearchForm = _IEFormGetObjByIndex ($o_IE, 0)
$o_Keywords = _IEFormElementGetObjByIndex ($o_SearchForm, "state")
_IEFormElementSetValue ($o_Keywords, $state)

How do I accomplish this? I think I understand the logic that it will take, but no idea how to set it up.

Some of the HTML:

<TR>
<TD class=plainText width="20%">State <SPAN class=smred>*</SPAN></TD>
<TD width="80%"><SELECT size=1 name=state> <OPTION value="" selected>Select a State</OPTION> <OPTION value=AL>Alabama</OPTION><OPTION value=AK>Alaska</OPTION><OPTION value=AZ>Arizona</OPTION><OPTION value=AR>Arkansas</OPTION><OPTION value=CA>California</OPTION></TD></TR>
<TR>

Dale, Thanks for the lesson in HTML!

Link to comment
Share on other sites

Select/Option, Checkbox and Radio elements are all rather confusing and don't work the way you would expect them to. I have thoughts about creating a Smart Set Value function that will work the way someone not familiar with the DOM would expect it to work... but later.

Here is specific code to address your situation:

$state = ClipGet ()
$o_SearchForm = _IEFormGetObjByIndex ($o_IE, 0)
$o_Keywords = _IEFormElementGetObjByIndex ($o_SearchForm, "state")
$o_Options = _IETagNameGetCollection($o_Keywords, "option")
For $o_Option in $o_Options
    If $o_Option.text = $state Then
        $o_Option.selected = True
        ExitLoop
    EndIf
Next

Behind the scenes an item, e.g. California, has a .value of CA and .text of California. In order to get the item you want highlighted, you need to use .selected = True on a specific item.

Dale

Edit: fixed typos

Edited by DaleHohm

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Select/Option, Checkbox and Radio elements are all rather confusing and don't work the way you would expect them to. I have thoughts about creating a Smart Set Value function that will work the way someone not familiar with the DOM would expect it to work... but later.

Here is specific code to address your situation:

$state = ClipGet ()
$o_SearchForm = _IEFormGetObjByIndex ($o_IE, 0)
$o_Keywords = _IEFormElementGetObjByIndex ($o_SearchForm, "state")
$o_Options = _IETagNameGetCollection($o_Keywords, "option")
For $o_Option in $o_Options
    If $o_Option.text = $state Then
        $o_Option.selected = True
        ExitLoop
    EndIf
Next

Behind the scenes an item, e.g. California, has a .value of CA and .text of California. In order to get the item you want highlighted, you need to use .selected = True on a specific item.

Dale

Edit: fixed typos

Awesome! Thanks for the code.

I did run into one problem that I should have taken notice of before, and I took about an hour to analyze the problem, then write out this LONG post on the forum, and right when I hit the 'preview post' and was about hit 'Add Post'--the solution hit me!

For Country I needed $o_Option.text, for State I needed $o_Option.value.

So selectall, delete my long post, and another many thanks!!!!!

Link to comment
Share on other sites

  • 1 year later...

Dale,

I was having the same sort of problem as litlmike - and your code solved my selection problem as well!

Problem I'm having right now is that the onchange() javascript doesn't get fired.

So the combobox value was the proper value visible but this new value doesn't get committed...

Any ideas?

Thanx,

Rick

Link to comment
Share on other sites

_IEFormElementOptionselect was added after this post... it fires the appropriate events for you. Check out the examples in the helpfile.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...