Jump to content
Sign in to follow this  
litlmike

_IEFormElementOptionSelect() & @error=5

Recommended Posts

litlmike

Below there is the code for my script, and the code for 2 different web pages - IE objects: $oIE_1 & $oIE_2. My question is does _IEFormElementOptionselect() have an issue with Elements that contain WhiteSpaces? If not, then why doesn't _IEFormElementOptionselect() report an @error with the following script? I ran into an issue a long time ago with _IEFormElementOptionselect() and WhiteSpaces which makes me wonder if this accounts for the peculiar behavior.

This script is copying data from 1 webpage to another. Sometimes in webpage $oIE_2 the Select (dropdown box) will not contain any of the same Options (HTML code shown below). If this is the case, I would like the script to produce a MsgBox alerting the user of the issue. In my script below, I would have thought that _IEFormElementOptionselect() would produce @error=5, because the Select Options do not share any of the same Values, but it does not produce any @error. Instead if the Value does not match, _IEFormElementOptionselect() will make the Select (dropdown box) blank, even though blank is not an option. Any ideas on how to arrive at the solution?

For $iCC = 1 To $FormElementNamesUBound
        $oForm = _IEFormGetObjByName ($oIE_1, "tripInfo")
        $oQuery = _IEFormElementGetObjByName ($oForm, $FormElementNames[$iCC])
        $Info2Pass = _IEFormElementGetValue ($oQuery)
        $oForm = _IEFormGetObjByName ($oIE_2, "tripInfo")
        $oQuery = _IEFormElementGetObjByName ($oForm, $FormElementNames[$iCC])
        _IEFormElementSetValue ($oQuery, $Info2Pass)
        ;This assumes that if the Value Cannot be Set, it must be an Optionselect
        If @error Then _IEFormElementOptionselect ( $oQuery, $FormElementNames[$iCC], 1, "byValue") ; , $f_select = 1 , "byValue")
        If @error Then MsgBox (0, "Error!", $FormElementNames[$iCC] & " - Option Elements are not Shared on Both Pages", 2)
    Next

HTML from $oIE_1

<select name="tripType" size=1>
<option value="Partially Guided">Partially Guided</option>
<option value="Fully Guided">Fully Guided</option>
<option value="Non Guided">Non Guided</option>
</select>

HTML from $oIE_2

<select name="tripType" size=1>
<option value="Walking Safari" >Walking Safari</option>
<option value="Guided Safari" selected>Guided Safari</option>
</select>

Share this post


Link to post
Share on other sites
DaleHohm

Sorry lilmike, the fact that you don't show the origin of all of the variables and that you overwrite the values of $oForm and $oQuery makes it very hard to follow what you are trying to do in that code. Can you simplify your code, make it self contained and ask a much more direct question?

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

Share this post


Link to post
Share on other sites
litlmike

Sorry lilmike, the fact that you don't show the origin of all of the variables and that you overwrite the values of $oForm and $oQuery makes it very hard to follow what you are trying to do in that code. Can you simplify your code, make it self contained and ask a much more direct question?

Dale

Here is a self-contained version. Thanks for the suggestion on how to move forward. The direct question(s) are:

1) Why doesn't _IEFormElementSetValue() produce an error when working with an 'Invalid Object Type', this example being with a Select Option?'

2) Why doesn't _IEFormElementOptionselect() produce an error when a value is not an option? So if the Option Values are 'A, B, C' and I _IEFormElementOptionselect() with a Value D, it gives no error.

This is the best way that I think I can ask the question directly. The idea behind the script is to set the Optionselect to a value, but when this value doesn't exist, then do X. I hope this helps. Thanks!

#include <IE.au3>

$oIE_1 = _IECreate("about:blank", 0 , 1, 1 )
$oIE_2 = _IECreate ("about:blank", 0 , 1, 1)

$StringA = '<FORM NAME="tripInfo" ACTION="gg_update_trips.cfm" METHOD="POST">' & '<select name="tripType" size=1>   <option value="Partially Guided">Partially Guided</option> <option value="Fully Guided">Fully Guided</option> <option value="Non Guided">Non Guided</option> </select>' & '</FORM>'
$StringB = '<FORM NAME="tripInfo" ACTION="gg_update_trips.cfm" METHOD="POST">' & '<select name="tripType" size=1> <option value="Walking Safari" >Walking Safari</option> <option value="Guided Safari" selected>Guided Safari</option> </select>' & '</FORM>'

_IEDocWriteHTML ($oIE_1, $StringA)
_IEDocWriteHTML ($oIE_2, $StringB)

    $oForm1 = _IEFormGetObjByName ($oIE_1, "tripInfo")
    $oQuery1 = _IEFormElementGetObjByName ($oForm1, "tripType")
    $Info2Pass = _IEFormElementGetValue ($oQuery1)
    ConsoleWrite ("'" & $Info2Pass & "'" & @CRLF)
    $oForm2 = _IEFormGetObjByName ($oIE_2, "tripInfo")
    $oQuery2 = _IEFormElementGetObjByName ($oForm2, "tripType")
    _IEFormElementSetValue ($oQuery2, $Info2Pass)
;~  ;This assumes that if the Value Cannot be Set, it must be an Optionselect
    If @error Then _IEFormElementOptionselect ( $oQuery2, $Info2Pass, 1, "byValue") ; , $f_select = 1 , "byValue")
    If @error Then MsgBox (0, "Error!", $Info2Pass & " - Option Elements are not Shared on Both Pages", 2)

Sleep (7000)
_IEQuit ($oIE_1)
_IEQuit ($oIE_2)

Share this post


Link to post
Share on other sites
DaleHohm

Ok, beautiful reproducer - thanks.

I think that your issues are caused by an understandable but invalid assumption about the "value" of a select object.

A select object does have a value, but it doesn't have a direct tie to the items in the drop-down menu. The value is what will be sent in the form data when it is submitted to the Web server. It is available as a convenience -- in older browser versions it didn't exist. By default, the value is the value of the first selected item in the select object but it can be set to anything because as I said, it has no direct tie to the actual items in the drop-down. You also must be careful to not trust the value from multiple select object because the value will be that of the first selected item and does not represent all of them. This is why you get no error if you try to set up to a value that's not represented by one of the members of the drop-down.

So, I think that what you're doing in the section that follows where you check the@error is the correct command. You need to check up front to see what kind of a form object you're working with. You can do this by checking the value of $oElement.type this will be select-single or select-multiple for select objects.

Makes sense?

Dale

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

Share this post


Link to post
Share on other sites
litlmike

Ok, beautiful reproducer - thanks.

I think that your issues are caused by an understandable but invalid assumption about the "value" of a select object.

A select object does have a value, but it doesn't have a direct tie to the items in the drop-down menu. The value is what will be sent in the form data when it is submitted to the Web server. It is available as a convenience -- in older browser versions it didn't exist. By default, the value is the value of the first selected item in the select object but it can be set to anything because as I said, it has no direct tie to the actual items in the drop-down. You also must be careful to not trust the value from multiple select object because the value will be that of the first selected item and does not represent all of them. This is why you get no error if you try to set up to a value that's not represented by one of the members of the drop-down.

So, I think that what you're doing in the section that follows where you check the@error is the correct command. You need to check up front to see what kind of a form object you're working with. You can do this by checking the value of $oElement.type this will be select-single or select-multiple for select objects.

Makes sense?

Dale

Ahhh, that does make sense, except for how knowing the $oElement.type will help. In that, I think it is select-single, but what would I do with that info, once I have it?

Here is a related question about making reproducers, "is there a better way to include the HTML in a script than how I did it above?" This seems okay in this example, since it is short, but what if I wanted to include several hundred lines of code to make a reproducer that is more representative of what I am working with.

TIA

Edited by litlmike

Share this post


Link to post
Share on other sites
DaleHohm

First, if it takes several hundred lines of HTML or code to explain, I'm betting you haven't done enough to narrow down the source of the problem. If it is absolutely necessary, then attach a seperate file.

Regarding $oElement.type -- it appeared to me taht you were relying on _IEFormElementSetValue to fail to determine what sort of input field you were targeting. The .type will tell you up front.

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

Share this post


Link to post
Share on other sites
litlmike

First, if it takes several hundred lines of HTML or code to explain, I'm betting you haven't done enough to narrow down the source of the problem. If it is absolutely necessary, then attach a seperate file.

Regarding $oElement.type -- it appeared to me taht you were relying on _IEFormElementSetValue to fail to determine what sort of input field you were targeting. The .type will tell you up front.

Dale

What you say is accurate about the several hundred lines comment; I exaggerated to make a point.

About $oElement.type, I have not used this method before, where can I find out what type of Returns are available? What you said is accurate, if _IEFormElementSetValue fails, then I know it is interacting with a drop down, not an Edit Field; but certainly having the script be able to interact with a field, based upon its type would be much more intelligent and eliminate many future issues. I would much prefer to go down this route.

Thanks again.

Share this post


Link to post
Share on other sites
DaleHohm

About $oElement.type, I have not used this method before, where can I find out what type of Returns are available? What you said is accurate, if _IEFormElementSetValue fails, then I know it is interacting with a drop down, not an Edit Field; but certainly having the script be able to interact with a field, based upon its type would be much more intelligent and eliminate many future issues. I would much prefer to go down this route.

So, that's my point. the SetValue will not fail, so your logic won't work... look at this:

#include <IE.au3>

$oIE = _IE_Example("form")
$oForm = _IEFormGetObjByName($oIE, "ExampleForm")
$oSelect = _IEFormElementGetObjByName($oForm, "selectExample")
$return = _IEFormElementSetValue($oSelect, "a bogus value litlmike")
If Not @error Then MsgBox(0, "You Expected An Error?", "You Didn't Get One!")

To learn about the other properties of the objects, you need to spend time in MSDN - see my sig, particularly the "DHTML Objects" link.

Dale

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

Share this post


Link to post
Share on other sites
litlmike

So, that's my point. the SetValue will not fail, so your logic won't work... look at this:

#include <IE.au3>

$oIE = _IE_Example("form")
$oForm = _IEFormGetObjByName($oIE, "ExampleForm")
$oSelect = _IEFormElementGetObjByName($oForm, "selectExample")
$return = _IEFormElementSetValue($oSelect, "a bogus value litlmike")
If Not @error Then MsgBox(0, "You Expected An Error?", "You Didn't Get One!")

To learn about the other properties of the objects, you need to spend time in MSDN - see my sig, particularly the "DHTML Objects" link.

Dale

I think I confused you last time around, I did understand your point that my logic would fail. I believe you were implying that I could use $oElement.type to determine if an object was of type "SELECT" or "INPUT". In other words, that if I knew more about MSDN, then I could then script a behavior based upon the "type". So a psuedo example would be:

$oIE = _IE_Example("form")
$oForm = _IEFormGetObjByName($oIE, "ExampleForm")
$oSelect = _IEFormElementGetObjByName($oForm, "selectExample")
If $oSelect = Type ("TEXT") Then _IEFormElementSetValue($oSelect, "a good value litlmike")
If $oSelect = Type ("SELECT") Then _IEFormElementOptionselect($oSelect, "a good value litlmike")

I am looking through MSDN to see if this type of detection is possible, but I have a hard time still making sense of MSDN. But, it seems that if this were possible, or this simple, you would have already implemented this in your UDF to that _IEFormElementSetValue() could self-determine this. Is my above example something that can even be accomplished? Thanks again.

Share this post


Link to post
Share on other sites
DaleHohm

Correct.

Here is the info for the Type property of a SELECT: http://msdn2.microsoft.com/en-us/library/m...702(VS.85).aspx

Here is the info for the Type property of an INPUT: http://msdn2.microsoft.com/en-us/library/m...700(VS.85).aspx

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

Share this post


Link to post
Share on other sites
litlmike

Correct.

Here is the info for the Type property of a SELECT: http://msdn2.microsoft.com/en-us/library/m...702(VS.85).aspx

Here is the info for the Type property of an INPUT: http://msdn2.microsoft.com/en-us/library/m...700(VS.85).aspx

Dale

Oh that is just lovely! I just added this to resolve the issues. Now looking back, I see that I had enough info to resolve this about 1-2 posts ago, but I am still a little dense on working with objects directly, so it took a bit for the fog in my brain to clear. Thanks so much for all your help on this. I love how you teach me to fish, not just give me a fish.

If $oQuery2.Type = "select-one" Then
            _IEFormElementOptionselect ( $oQuery2, $Info2Pass1, 1, "byText") ; , $f_select = 1 , "byValue")
        Else 
            _IEFormElementSetValue ($oQuery2, $Info2Pass1)
        EndIf

Share this post


Link to post
Share on other sites
DaleHohm

...and I love a good student.

You're welcome.

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

Share this post


Link to post
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
Sign in to follow this  

×