Jump to content
Sign in to follow this  

radio buttons without form

Recommended Posts



I've got a page I need to interact with that has input elements not within a form The text fields I can manipulate using an object identifier, but I can't see how to get _IEFormElementRadioSelect working without a form reference/handle. I also need to do some select lists that are outside of the form, but I've not looked at those yet. I've build myself a tiny test page to play with.



<input id="text" type="text" size="40" onclick="alert('text')"/>

<input id="vat1" type="radio" name="vat-payable" value="Don't know" onclick="alert('radio 1')" />

<input id="vat2" type="radio" name="vat-payable" value="Yes" onclick="alert('radio 2')" />

<input id="vat3" type="radio" name="vat-payable" value="No" onclick="alert('radio 3')" />



Any insight/hacks would be appreciated.



Share this post

Link to post
Share on other sites

#include <IE.au3>
$oHTML = "<html>" & @CRLF
$oHTML &= "<body>" & @CRLF
$oHTML &= "<input id=""text"" type=""text"" size=""40"" onclick=""alert('text')""/>" & @CRLF
$oHTML &= "<input id=""vat1"" type=""radio"" name=""vat-payable"" value=""Don't know"" onclick=""alert('radio 1')"" />" & @CRLF
$oHTML &= "<input id=""vat2"" type=""radio"" name=""vat-payable"" value=""Yes"" onclick=""alert('radio 2')"" />" & @CRLF
$oHTML &= "<input id=""vat3"" type=""radio"" name=""vat-payable"" value=""No"" onclick=""alert('radio 3')"" />" & @CRLF
$oHTML &= "</body>" & @CRLF
$oHTML &= "</html>"
$oIE = _IECreate()
_IEDocWriteHTML($oIE, $oHTML)
$oInput1 = _IEGetObjById($oIE, "text")
$oInput2 = _IEGetObjById($oIE, "vat1")
$oInput3 = _IEGetObjById($oIE, "vat2")
$oInput4 = _IEGetObjById($oIE, "vat3")
_IEFormElementSetValue($oInput1, "text")
_IEAction($oInput2, "click")
_IEAction($oInput3, "click")
_IEAction($oInput4, "click")

Share this post

Link to post
Share on other sites

Hi, Thanks, that did the job. Cheers, Bob

Share this post

Link to post
Share on other sites

If you are lucky enough to have ID's on all of those elements, them that is a very good solution. Note that _IEFormElementSetValue will do what you want for an INPUT TYPE=TEXT element, but for other elements you will most likely want to use _IEAction($oElement, "click") -- this is because you do not want to change the VALUE of those elements, but rather make certain the you select the one(s) with the value that you want.

SELECT OPTION (drop-down, select and multi-select controls) are more complicated. The SELECT element in turn has a .OPTION collection under it. The SELECT has a NAME and the OPTIONs have both .text and .value properties. This all makes these things very confusing. Noteas as well that SELECT OPTION, RADIO and CHECKBOX elements all have a .checked property (TRUE or FALSE) that reveal or control whether they are selected or not.

I have not worked out a generalized way to do all of this in IE.au3 when the elements are not in a form, but unfortunately, it is becomming more common practice.

You may also find this approach useful:

$oInputs = _IETagNameGetCollection($oIE, "input") 
For $oInput in $oInputs
    ; do some tests
    ; take some action


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