chachew Posted February 8, 2011 Share Posted February 8, 2011 What i am wanting to do is to have 2 radio buttons on my form and then a start button that will perform the task associated with which ever radio button is selected. Im not sure where to go exactly, will this be an IF...Else statement? I was thinking of something to the effect of: If $Radio1 = true then $url = "www.mysite.net" If $Radio2 - true then $url = "www.test.site.net" #include <IE.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Radio1 = ($url, "www.mysite.net") $Radio2 = ($url, "www.test.site.net") Func StartTest() $IE = _IECreate($url) $Form1 = _IEFormGetObjByName ($IE,"form1"); Name of the Login page $Username = _IEFormElementGetObjByName ($Form1, "txtUsername"); Data that will be entered into the username field $Password = _IEFormElementGetObjByName ($Form1, "txtPassword"); Data that will be entered into the password field $Submit = _IEFormElementGetObjByName($Form1, "btnSubmit"); ID of the submit button _IEFormElementSetValue ($Username, "admin") Sleep(1000) _IEFormElementSetValue ($Password, "password") Sleep(1000) _IEAction($Submit, "click"); Must use _IEAction for javascript code EndFunc $GUIForm1 = GUICreate("Start Login", 328, 145, 192, 124) $Button1 = GUICtrlCreateButton("Start Testing", 8, 64, 145, 49) ;$Button2 = GUICtrlCreateButton("Stop", 168, 64, 145, 49) $Radio1 = GUICtrlCreateRadio("Production", 24, 16, 113, 17) $Radio2 = GUICtrlCreateRadio("Staging", 24, 40, 113, 17) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() if $nMsg = -3 Then Exit Switch GUIGetMsg() Case $Button1 StartTest() EndSwitch WEnd Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 8, 2011 Moderators Share Posted February 8, 2011 mkirkland,An If...Else...EndIf would be better then multiple Ifs: #include <GUIConstantsEx.au3> $url1 = "www.mysite.net" $url2 = "www.test.site.net" $hGUI = GUICreate("Test", 500, 500) $GUIForm1 = GUICreate("Start Login", 328, 145, 192, 124) $Button1 = GUICtrlCreateButton("Start Testing", 8, 64, 145, 49) ;$Button2 = GUICtrlCreateButton("Stop", 168, 64, 145, 49) $Radio1 = GUICtrlCreateRadio("Production", 24, 16, 113, 17) $Radio2 = GUICtrlCreateRadio("Staging", 24, 40, 113, 17) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $Button1 ; Use GUICtrlRead to get the state of the radio If GUICtrlRead($Radio1) = 1 Then $url_to_use = $url1 ; If it is not one then it must be the other! Else $url_to_use = $url2 EndIf MsgBox(0, "Using", $url_to_use) EndSwitch WEndAll clear? M23P.S. When you post code please use Code tags. Put [autoit] before and [/autoit] after your posted code. Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
chachew Posted February 8, 2011 Author Share Posted February 8, 2011 Melba23, i have made the changes that you suggested but when i select a radio button and click $Button1 and nothing happens exept a Msgbox pop which i have removed. I dont want the msgbox to display but when $button1 is clicked i want Func StartTest() to run $IE based on the radio button selected. Also what is the purpose of $hGUI that you added to the code? expandcollapse popup#include <IE.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Func StartTest() $IE = _IECreate($url_to_use) $Form1 = _IEFormGetObjByName ($IE,"form1"); Name of the Login page $Username = _IEFormElementGetObjByName ($Form1, "txtUsername"); Data that will be entered into the username field $Password = _IEFormElementGetObjByName ($Form1, "txtPassword"); Data that will be entered into the password field $Submit = _IEFormElementGetObjByName($Form1, "btnSubmit"); ID of the submit button _IEFormElementSetValue ($Username, "admin") Sleep(1000) _IEFormElementSetValue ($Password, "password") Sleep(1000) _IEAction($Submit, "click"); Must use _IEAction for javascript code EndFunc $urlProd = "www.mysite.net" $urlStage = "www.test.site.net" ;$hGUI = GUICreate("Test", 500, 500) $GUIForm1 = GUICreate("Start Login", 328, 145, 192, 124) $Button1 = GUICtrlCreateButton("Start Testing", 8, 64, 145, 49) ;$Button2 = GUICtrlCreateButton("Stop", 168, 64, 145, 49) $Radio1 = GUICtrlCreateRadio("Production", 24, 16, 113, 17) $Radio2 = GUICtrlCreateRadio("Staging", 24, 40, 113, 17) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $Button1 ; Use GUICtrlRead to get the state of the radio If GUICtrlRead($Radio1) = 1 Then $url_to_use = $urlProd ; If it is not one then it must be the other! Else $url_to_use = $urlStage EndIf EndSwitch WEnd Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 8, 2011 Moderators Share Posted February 8, 2011 mkirkland, That was a proof of concept script to show you how to interrogate the radios, not a full solution. You said: "Im not sure where to go exactly", so I showed you, but left it to you to integrate the concept into your own script. However, as you seem to want more..... The code I posted shows you how to get the correct URL. You then pass that URL to your function as a parameter: While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $Button1 ; Use GUICtrlRead to get the state of the radio If GUICtrlRead($Radio1) = 1 Then Func StartTest($urlProd) ; Run the function with this URL ; If it is not one then it must be the other! Else Func StartTest($urlStage) ; Run the function with this URL EndIf EndSwitch WEnd Then in your function you use the parameter as follows: Func StartTest($url) ; The parameter holds the URL we sent $IE = _IECreate($url) ; And we use it here ..... All clear? M23 P.S. what is the purpose of $hGUI that you added to the code?An oversight from the copy-paste I did of your code into my normal template. Just delete it. Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
chachew Posted February 8, 2011 Author Share Posted February 8, 2011 (edited) Sorry for all the back and forth..im new to AutoIT and new to programming in any language at that.. So i now have: Func StartTest($url_to_use) $IE = _IECreate($url_to_use) Is that correct because we are wanting to use the set URL value based on the radio button selection. So If GUICtrlRead($Radio1) = 1 Then $url_to_use = $urlProd Else $url_to_use = $urlStage endif It get the script to run with no errors but get no action when the $Button1 is pressed so i guess im missing something. Edited February 8, 2011 by mkirkland Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 8, 2011 Moderators Share Posted February 8, 2011 mkirkland,Did you actually look at the code I posted? If you had you would see that I was calling the function from within the Case statements, not setting the variable. I will post it again - look for the <<<<<<<<<< lines:While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $Button1 ; Use GUICtrlRead to get the state of the radio If GUICtrlRead($Radio1) = 1 Then Func StartTest($urlProd) ; Run the function with this URL <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ; If it is not one then it must be the other! Else Func StartTest($urlStage) ; Run the function with this URL <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EndIf EndSwitch WEndThere is no need to apologise for being new - we were all at that stage once. But please do look carefully at the answers you get - especially when you have just complained that you did not get exactly what you wanted the first time. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Oviyaa Posted February 10, 2011 Share Posted February 10, 2011 Informative sharing .. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now