Sign in to follow this  
Followers 0
jjj

Ie Udf Help With Selecting Radio Buttons

9 posts in this topic

I am having problem understanding the IE udf. What I am trying to do is select the first radio button on this page, (it is for my router) and then hit the "edit" button (type=submit).

I cant get anything to work, so i think i am having problems understanding how to start.

If anyone can help me get started, or send me a script that does something similar i would be able to figure it out. Thanks!

#include <IE.au3>
$oIE = _IECreateEmbedded ()
GUICreate("Embedded Web control Test", 640, 580, (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 600, 360)
GUISetState()    
_IENavigate ($oIE, "http://192.168.0.1/pforward.htm")
$collection = _IEFormElementGetCollection ( $oIE )
$firststate = _IEFormElementRadioSelect ( "routeselect", 7 , 1 , "byIndex" , 0 )

webpage source:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="description" content="MR814v3 2022">

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<META http-equiv="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">    
<meta HTTP-EQUIV="Expires" CONTENT="Mon, 06 Jan 1990 00:00:01 GMT"> 



<title>Port Forwarding</title>
<link rel="stylesheet" href="form.css">
<STYLE TYPE="text/javascript">
    classes.num.all.fontFamily = "Courier";
    classes.num.all.fontSize = "10pt";
</style>
<script language="javascript" type="text/javascript" src="utility.js"></script>
<script language="javascript" type="text/javascript">
<!-- hide script from old browsers
function loadhelp(fname,anchname) {
if ((loadhelp.arguments.length == 1 ) || (anchname == "" ))
    top.helpframe.location.href="h"+fname+".htm";
else
    top.helpframe.location.href="h"+fname+".htm#" + anchname;
}
function chgSel(index)
{
 document.forms[0].select.value = index;
 return true;
}
function validIp()
{
 var cf = document.forms[0];
 if( (cf.SV_IP4.value=="0") || checkIP(cf.SV_IP1,cf.SV_IP2,cf.SV_IP3,cf.SV_IP4,254))
 return alertR(msg_invalid_ip);
 return true; 
}
//-->
</script>
</head>
<body bgcolor="#ffffff" onload="loadhelp('forw');">
<form name="formname" method="POST" action="pforward.cgi">
<table border="0" cellpadding="0" cellspacing="3" width="100%">
<tr> 
 <td colspan="2"><h1>Port Forwarding</h1></td>
</tr>
<tr> 
 <!-- RULE -->
 <td colspan="2" background="liteblue.gif" height="12">  </td>
</tr>
<tr> 
 <td width="45%" valign="top"><a href="java script:loadhelp('forw','setup')" tabindex="-1"><b>Service Name</b></a></td>
 <td width="65%"><a href="java script:loadhelp('forw','setup')" tabindex="-1"><b>Server IP Address</b></a></td>
</tr>
<tr>
 <td valign="top">
    <select name="svs_gm" size="1" tabindex="1" onchange="this.form.submit()"><option>AIM</option><option>Age of Empire</option><option>FTP</option><option>HTTP</option><option>ICUII</option><option>IP_Phone</option><option>NetMeeting</option><option>News</option><option>PPTP</option><option>QuakeII/III</option><option>Real-Audio</option><option>Telnet</option></SELECT></td>
 <td nowrap><input type="text" name="SV_IP1" class="num" size="4" maxlength="3" value="192" onfocus="this.select();" tabindex="2">.<input type="text" name="SV_IP2" class="num" size="4" maxlength="3" value="168" onfocus="this.select();" tabindex="3">.<input type="text" name="SV_IP3" class="num" size="4" maxlength="3" value="0" onfocus="this.select();" tabindex="4">.<input type="text" name="SV_IP4" class="num" size="4" maxlength="3" value="" onfocus="this.select();" tabindex="5">
    <input type="Submit" name="svAdd" value="Add" tabindex="6" onclick="return validIp();"></td>
</tr>
<tr> 
 <!-- RULE -->
 <td colspan="2" background="liteblue.gif" height="12">  </td>
</tr>
<tr><td colspan="2">
        <table border ="1" cellpadding ="0" cellspacing ="0" width="100%">
            <tr>
                <td nowrap width="3%" align="center"><span class="thead"> </span></td>
                <td nowrap width="3%" align="center"><span class="thead">#</span></td>
            <td nowrap width="30%" align="center"><span class="thead">Service Name</span></td>
                <td nowrap width="12%" align="center"><span class="thead">Start Port</span></td>
                <td nowrap width="12%" align="center"><span class="thead">End Port</span></td>
                <td nowrap width="27%" align="center"><span class="thead">Server IP Address</span></td>
            </tr><tr><td nowrap align="center"><span class="thead"> <input type="RADIO" name="RouteSelect"  checked value="0" onclick="chgSel(0);"></span></td><td nowrap align="center"><span class="thead">1</span></td><td nowrap align="center"><span class="ttext">SKYPE</span></td><td nowrap align="center"><span class="ttext">4999</span></td><td nowrap align="center"><span class="ttext">5000</span></td><td nowrap align="center"><span class="ttext">192.168.0.5</span></td></tr><tr><td nowrap align="center"><span class="thead"> <input type="RADIO" name="RouteSelect" value="1" onclick="chgSel(1);"></span></td><td nowrap align="center"><span class="thead">2</span></td><td nowrap align="center"><span class="ttext">AOL-IM</span></td><td nowrap align="center"><span class="ttext">7000</span></td><td nowrap align="center"><span class="ttext">7001</span></td><td nowrap align="center"><span class="ttext">192.168.0.5</span></td></tr></table>
        </td>
</tr>

<tr> 
 <!-- RULE -->
 <td colspan="2" background="liteblue.gif" height="12">  </td>
</tr>

 
<tr><td colspan="2" align="center" height="35" valign="bottom">
    <input type="Submit" name="Edit" value="  Edit Service  " tabindex="8">
    <input type="Submit" name="Delete" value="Delete Service" tabindex="9">
<BR><BR>
    <input type="Submit" name="Add" value="Add Custom Service" tabindex="7">

    <input type="hidden" name="select" value="0">
</td></tr>
 </table>
</form>
</body>
</html>

Share this post


Link to post
Share on other sites



Here's an example using the new _IE_Example() function that simply creates a page with a bunch of form elements on it for testing...

#include <IE.au3>
$oIE = _IE_Example("form")

$oForm = _IEFormGetObjByName($oIE, "ExampleForm")
_IEFormElementRadioSelect($oForm, 0, "radioExample", 1, "byIndex")
;_IEFormSubmit($oForm)

This will select the first radio button (index-0) in the radio group named "radioExample".

Feedback on what makes this confusing (besides a lack of an example - I'll submit one for the next release of the docs) is 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

#3 ·  Posted (edited)

This should do want you are wanting, I added comments to help explain what it's doing.

#include <IE.au3>
#include <GuiConstants.au3>

_IEErrorHandlerRegister()

$oIE = _IECreateEmbedded ()
GUICreate("Embedded Web control Test", 640, 580, (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 600, 360)
GUISetState()

_IENavigate ($oIE, "http://192.168.0.1/pforward.htm")

; get a object variable reference to the form
$oForm = _IEFormGetObjByName($oIE, "formname")
; get an object variable reference to the edit button
$oEdit = _IEFormElementGetObjByName($oForm, "Edit")
; select the radio button in group "RouteSelect" and vaule "0"
$firststate = _IEFormElementRadioSelect($oForm, 0, "RouteSelect")
; click the edit button
_IEAction($oEdit, "click")

@Dale - I just noticed a couple syntax errors in the help files, I'll get those corrected. Also for _IEFormElementRadioSelect we have $o_object = Form Element Object of type "Input Type=Radio", which sounds like it should be the radio button itself.

Edited by big_daddy

Share this post


Link to post
Share on other sites

Ah, except he said he wanted the first radio button rather than the one with a value of 0... it that is that case, then he wants this instead

; select the 1st (index-0) radio button in group "RouteSelect"
$firststate = _IEFormElementRadioSelect($oForm, 0, "RouteSelect", 1, "byIndex")

@Dale - I just noticed a couple syntax errors in the help files, I'll get those corrected. Also for _IEFormElementRadioSelect we have $o_object = Form Element Object of type "Input Type=Radio", which sounds like it should be the radio button itself.

Yes, you're right... that would sure make it harder to understand...

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

Ah, except he said he wanted the first radio button rather than the one with a value of 0... it that is that case, then he wants this instead

; select the 1st (index-0) radio button in group "RouteSelect"
$firststate = _IEFormElementRadioSelect($oForm, 0, "RouteSelect", 1, "byIndex")
I'm confused, doesn't that do the same thing as mine? The first radio has a value of "0" and the second "1".

Yes, you're right... that would sure make it harder to understand...

Dale

It actually got me at first, I'll try to reword it.

Share this post


Link to post
Share on other sites

I'm confused, doesn't that do the same thing as mine? The first radio has a value of "0" and the second "1".

:"> Yep, you're right. Now he has two choices... one example byValue and one byIndex.

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

ok, it worked perfectly, but I am confused as to why it worked.

From the help file for _IEFormElementRadioSelect , the usage is:

_IEFormElementRadioSelect ( $o_object, $s_string [, $f_select = 1 [, $s_mode = "byValue" [, $f_fireEvent = 1]]] )

your line is _IEFormElementRadioSelect($oForm, 0, "RouteSelect")

what is "RouteSelect" doing in there? From the help file, it should be $f_select, am i right?

Thanks for the help!

Share this post


Link to post
Share on other sites

Sorry, documentation error... thanks for catching it. I had been worried that no one had posted feedback on this new set of form functions. I'm glad you are exercising them. I packed a lot of functionality into them so that I could cover the need with 3 functions instead of 7 (but they are more complex).

It should be:

_IEFormElementRadioSelect ( $o_object, $s_string, $s_name [, $f_select = 1 [, $s_mode = "byValue" [, $f_fireEvent = 1]]] )

where $s_name is the radioGroup name.

It is the same for the Checkbox function except that $s_name is optional for that function and required for radios.

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

great! I've got it working now, thanks for all the help!

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  
Followers 0