Jump to content

auto select radio buttons


Recommended Posts

I'm a newbie.  It will be apparent shortly  :.  I have read the help files and seen several tutorials.  My goal is to write a script to automate the selection of particular radio buttons on a particular webpage.  I think i can write the script ok if i can get the correct info from the Window Info tool.  The problem i am having is that when i move my cursor (or the crosshairs) across the desired webpage, the ONLY thing that changes on the CONTROL tab or the MOUSE tab is the ControlClick Coords or the Position.  I believe that what I need to write my script is the Title and the Class info.  But that info never changes as i move the cursor.  I know that the window title info applies to the entire window (webpage) i am viewing, but don't i need to drill further and get info on the specific radio buttons on that particular webpage that i wish to identify and hence auto-select for my script?

Not sure how far off base i am with this, but i have spent considerable time on this.  Not looking for a free-ride here, but i just need a little jumpstart to help me understand.

Thanks for any help you could provide.

(note:  i have successfully written an AHK script that works fine using the coordinates and mouse clicks, etc.....  it works great.  The problem is that this particular website keeps changing - from day to day - the info (content) on the page, hence the coordinates change and it messes up my script.  Instead of using fixed coordinates to mouseclick the radio buttons, i want to use the correct Controls to identify and select the radio buttons)

Jev

Link to comment
Share on other sites

Use the _IE* functions to automate the webpage.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

maybe if you give us an example of the website link then we can help you from there. Myself still have difficulty on automating, but won't hurt to try something new.

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

Thanks queen!  Check this:  https://www.sewp.nasa.gov/vendor/       What i am trying to do is to automate my login, and then a click a few more buttons after logging in.  First i need to add my company name from the dropdown under VENDOR ID.  Then type in my user ID, then password.  Then click login, etc...  After that, a few more clicks.  Obviously, trying to automate that whole process.  As i said in my post, i have written an AHK script to do all of the above.  But the website content keeps CHANGING daily so that the x and y mouse coordinates become useless.  I need a better way to automate it.  That may very well be the use of the _IE functions, but i am not skilled with those yet.

Thanks for trying to help!

Jev

Link to comment
Share on other sites

This works for me

#include <IE.au3>

Local $oIE = _IECreate("https://www.sewp.nasa.gov/vendor/")
Sleep(1000)
$oSelect = _IEGetObjByName($oIE, "vendor_list")
$oSelect.Focus()
$oSelect.options.value = "14"   ;<<< choose in the html source the one you want
$oSelect.fireEvent("onChange")
$oInputs = _IETagNameGetCollection($oIE, "input")
For $oInput In $oInputs
    If $oInput.name == "uid" Then $oInput.innertext = "jevbrowser"  
    If $oInput.name == "pwd" Then $oInput.innertext = "1234"  
    If $oInput.type == "submit" Then $oSubmit = $oInput
Next
$oSubmit.Focus()
$oSubmit.Click()

But obviously I can't do more as I get a "access denied" message  :)

Edit : correction input names

Edited by mikell
Link to comment
Share on other sites

Mikell,

THANK YOU SO MUCH!!!!!!!!!  What a huge help!!!!  I have one more question:  I need to select a button after i log in but i don't know what command to add to the script file.  i can show you in an attachment.  is there a way i could get an attachment to you?

thanks,

Jev

Link to comment
Share on other sites

here is what the source code looks like after i login:

function old_build_vendor_menu(){
  /* used on all Vendor Only web pages */
  //alert("start function old_build_vendor_menu");
  var myMenu = '<FORM ID="MENU" NAME="MENU" METHOD="post">n';
  myMenu += '<TABLE BORDER="0" ALIGN="center" CELLPADDING="2" CELLSPACING="0" CLASS="table_font" NOWRAP>n';
  //--------------- first row ----------------
  myMenu += '<TR ALIGN="center" NOWRAP>n';
  myMenu += '<TD ALIGN="center" VALIGN="middle" NOWRAP CLASS="CHOP_header_text_graphic">n';
   myMenu += '      <INPUT TYPE="button" NAME="vendor_home" VALUE="CHOP Home" CLASS="button" onClick="document.MENU.action = ';
   myMenu += "'https://"+document.domain+"/cgi-bin/log_in.pl'";
   myMenu += '; document.MENU.ACTION.value = '+"'HOME'"+'; return isVendorId('+"'MENU'"+');">n';
  myMenu += '    <IMG SRC="/images/1pixel.gif" WIDTH="10" HEIGHT="1">n';
   myMenu += '      <INPUT TYPE="button" NAME="clin_check" VALUE="CLIN Checker" CLASS="button" onClick="OpenInNewWin(';
   myMenu += "'https://"+document.domain+"/cgi-bin/clin_checker.pl'";
   myMenu += ', '525', '850');">n';
  myMenu += '    <IMG SRC="/images/1pixel.gif" WIDTH="10" HEIGHT="1">n';
   myMenu += '      <INPUT TYPE="button" ID="clin_list_menu" NAME="clin_list_menu" VALUE="CLIN List" CLASS="button" onClick="document.MENU.action=';
   myMenu += "'https://"+document.domain+"/sewp/jsp/ViewClinList.action'";
   myMenu += '; document.MENU.ACTION.value = ';
   myMenu += "' '";
etc...........................
 
i want to click on the "CLIN List" button.  So which part of the source code would i add to my script to do that?
 
jev
Link to comment
Share on other sites

wow Mikell!  worked great.  i am only missing ONE last piece here.  I can't find the correct source code to click on the hyperlink that will create the Tab Delimited download for me.  Here is the source code:

   <td colspan="2"><div align="right"><input type="submit" id="viewClinListForm_FindClins" name="action:FindClins" value="Search"/>
</div></td>
</tr>
 
</table>
 
 
 
 
<div id="exportlink">
Click To Download All CLINs For The Selected Manufacturer In
 
 
 
 
<a href='/sewp/jsp/ExportClins.action?format=csv&amp;selectedManufacturer=All'><span class="export csv"> CSV </span></a>
Format or as a
 
 
 
 
<a href='/sewp/jsp/ExportClins.action?format=tab&amp;selectedManufacturer=All'><span class="export csv"> Tab Delimited </span></a>
File
</div>
 
 
<span class="pagebanner">413919 items found, displaying 1 to 25.</span>
<span class="pagelinks">
 
[First/Prev]<b>1</b>
 
 
The last good part of my script includes the first line of this above code which is the "action:FindClins"
After my script gets thru that section, the screen has a hyperlink that says:  "Tab Delimited".  Can you help me with this last line for the script file that will invoke that Tab Delimited command?
 
thanks,
Jev
Link to comment
Share on other sites

Mikell,

i get the following syntax error WITH or WITHOUT the white space:

"L:downloadsutilitiesAutoIT V3 updatedmy scripts_IEFormSubmit_NASA_V2.au3"(33,41) : error: syntax error
_IELinkClickByText($oIE, "Tab Delimited"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
L:downloadsutilitiesAutoIT V3 updatedmy scripts_IEFormSubmit_NASA_V2.au3 - 1 error(s), 0 warning(s)
>Exit code: 2    Time: 0.061
 
What do you think it could be?
 
thanks,
Jev
Link to comment
Share on other sites

yes, i DID forget the trailing paren, but i fixed it and i don't get the syntax error anymore, but the last command we are working on to click on the Tab Delimited link is still not working.  The script just finishes with its last command being this apparently:

$oButton = _IEGetObjByName($oIE, "action:FindClins")
$oButton.Focus()
$oButton.Click()
 
Here is the entire script so far:
 
#include <IE.au3>
 
Local $oIE = _IECreate("https://www.sewp.nasa.gov/vendor/")
Sleep(1000)
$oSelect = _IEGetObjByName($oIE, "vendor_list")
$oSelect.Focus()
$oSelect.options.value = "14"   ;<<< choose in the html source the one you want
$oSelect.fireEvent("onChange")
$oInputs = _IETagNameGetCollection($oIE, "input")
For $oInput In $oInputs
    If $oInput.name == "uid" Then $oInput.innertext = "username"
    If $oInput.name == "pwd" Then $oInput.innertext = "password!"
    If $oInput.type == "submit" Then $oSubmit = $oInput
Next
$oSubmit.Focus()
$oSubmit.Click()
While $oIE.busy   ; add this to wait for complete loading of the new page
  Sleep(1000)
Wend
 
$oButton = _IEGetObjByName($oIE, "clin_list_menu")
$oButton.Focus()
$oButton.Click()
Sleep (20000)
$oSelect = _IEGetObjByName($oIE, "selectedManufacturer")
$oSelect.Focus()
$oSelect.options.value = "All"
Sleep (10000)
$oButton = _IEGetObjByName($oIE, "action:FindClins")
$oButton.Focus()
$oButton.Click()
Sleep (5000)
$oLinks = _IELinkGetCollection($oIE)
For $oLink In $oLinks
    If StringInStr($oLink.innertext, "Delimited") Then $oLink.Click()
Next

 

But as i said, the script just finishes but never activates that "Tab Delimited" hyperlink.

thanks,

Jev

Link to comment
Share on other sites

Maybe there's just a missing focusing

For $oLink In $oLinks
    If StringInStr($oLink.innertext, "Delimited") Then 
        $oLink.Focus()
        $oLink.Click()
        Exitloop
    EndIf
Next

Do the previous instructions work correctly ? Is there a new page loading after the "action:FindClins" click ? If so you can try

_IELoadWait($oIE)

just before the Tab thing

and please, use the "code" tag when you post html or autoit code otherwise the moderators will grow dark :)

Link to comment
Share on other sites

Using my signature:

$xpathLinks = "//span[@class='export csv' and contains(.,'Delimited')]"
$aMatchingLinks = BGe_IEGetDOMObjByXPathWithAttributes($oIE,$xpathLinks)
ConsoleWrite("Matching Links=[" & UBound($aMatchingLinks) & "]" & @CRLF)
For $i = 0 To UBound($aMatchingLinks)-1
    _IEAction($aMatchingLinks[$i],"focus")
    _IEAction($aMatchingLinks[$i],"click")
Next

If the consolewrite is "Matching Links=[0]", then the link is probably within a Frame.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Mikell,

Here is what i have now for the last 2 commands:

$oButton = _IEGetObjByName($oIE, "action:FindClins")
$oButton.Focus()
$oButton.Click()
Sleep (5000)
_IELoadWait($oIE)
For $oLink In $oLinks
    If StringInStr($oLink.innertext, "Delimited") Then
        $oLink.Focus()
        $oLink.Click()
        Exitloop
    EndIf
Next

The "action:findClins" works good.  Then, the script just ends and no Tab Delimited command is run.

thanks,

Jev

Link to comment
Share on other sites

Grab the link collection, fresh, after the click.  Seems your page is refreshing, right?  You need to grab the current pages links.

Else, you are attempting to click links that are no longer present (maybe).

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Thanks JD.  But the page definitely has time to fully load.

Here is the source code on the final loaded page where i am trying to get the Tab Delimited hyperlink to run:

    <td colspan="2"><div align="right"><input type="submit" id="viewClinListForm_FindClins" name="action:FindClins" value="Search"/>
</div></td>
</tr>

</table>

<div id="exportlink">
Click To Download All CLINs For The Selected Manufacturer In

<a href='/sewp/jsp/ExportClins.action?format=csv&amp;selectedManufacturer=All'><span class="export csv"> CSV </span></a>
Format or as a

<a href='/sewp/jsp/ExportClins.action?format=tab&amp;selectedManufacturer=All'><span class="export csv"> Tab Delimited </span></a>
File
</div>

<span class="pagebanner">413920 items found, displaying 1 to 25.</span>
<span class="pagelinks">

[First/Prev]<b>1</b>

Again, the "action:FindClins" command runs fine in my script and that page loads completely.  I just can't get the very last Tab Delimited link to run.

thanks,

Jev

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...