goku200 Posted May 1, 2020 Posted May 1, 2020 My code at the moment only select the first checkbox when looping. However, my other checkboxes are not selected when iterating. Is there something wrong with my for loop and if so how do iterate it and select all the other checkboxes? HTML Code: <input type="checkbox" name="city01"> <lable for="city">Detroit</label> <br> <input type="checkbox" name="city01"> <lable for="city">Chicago</label> <br> <input type="checkbox" name="city01"> <lable for="city">New York</label> <br> <input type="checkbox" name="city01"> <lable for="city">Miami</label> <br> And for my Autoit code: #include <IE.au3> $url = "checkbox.html" $oIE = _IECreate ($url, 1) $oForm = _IEFormGetCollection($oIE, 0) For $i = 0 To $oForm.length - 1 _IEFormElementCheckboxSelect($oForm, 0, "city01", 1, "byIndex", 1) Next
goku200 Posted May 1, 2020 Author Posted May 1, 2020 10 minutes ago, faustf said: is possible have link of page web? Here is a link: https://codepen.io/j1osu2006/pen/MWaEBmo
faustf Posted May 1, 2020 Posted May 1, 2020 try this #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <File.au3> #include <IE.au3> #include <Array.au3> #include <INet.au3> Global $iCont_truck = 0, $iGTimeToCeckTruck = 1000, $iGTimeOutTruck = 1000, $oIE _start() Func _start() If ProcessExists("iexplore.exe") Then ; Check if the internet esplorer process is running. ProcessClose("iexplore.exe") EndIf $oIE = _IECreate("https://codepen.io/j1osu2006/pen/MWaEBmo", 0, 1, 1, 1) ; <--- 0011 invisible explorer <--- 0111 visible explorer _IELoadWait($oIE, $iGTimeToCeckTruck, $iGTimeOutTruck) Local $sLBodyHtl = _IEBodyReadHTML($oIE) Local $oBtns = $oIE.document.GetElementsByTagName("input") For $oBtn In $oBtns $id = String($oBtn.name()) ; ConsoleWrite($id & @CRLF) If $id = "city01" Then _IEAction($oBtn, "click") ; _IEFormElementSetValue($oBtn, $sUser) EndIf Next EndFunc ;==>_start
Danp2 Posted May 1, 2020 Posted May 1, 2020 @goku200 Change your script so that you pass the variable $i as a parameter, like this -- _IEFormElementCheckboxSelect($oForm, $i, "city01", 1, "byIndex", 1) Now it should trigger each checkbox. Be aware that your code will break if the form contains more than just checkbox elements. Latest Webdriver UDF Release Webdriver Wiki FAQs
Subz Posted May 1, 2020 Posted May 1, 2020 Maybe use something like (it won't work on your example since the page doesn't support IE and it doesn't have form tag): #include <IE.au3> $url = "https://www.ericmmartin.com/code/jquery/checkbox.html" $oIE = _IECreate ($url, 1) $oForm = _IEFormGetCollection($oIE, 0) $oInputs = _IEFormElementGetCollection($oForm, -1) For $i = 0 To $oInputs.length - 1 If $oInputs($i).type = "checkbox" Then $oCheckbox = $oInputs($i) _IEFormElementCheckboxSelect($oForm, $i, "", 1, "byIndex") EndIf Next @Faust - Would be easier just to use _IETagNameGetCollection($oIE, "input")
goku200 Posted May 1, 2020 Author Posted May 1, 2020 43 minutes ago, faustf said: try this #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <File.au3> #include <IE.au3> #include <Array.au3> #include <INet.au3> Global $iCont_truck = 0, $iGTimeToCeckTruck = 1000, $iGTimeOutTruck = 1000, $oIE _start() Func _start() If ProcessExists("iexplore.exe") Then ; Check if the internet esplorer process is running. ProcessClose("iexplore.exe") EndIf $oIE = _IECreate("https://codepen.io/j1osu2006/pen/MWaEBmo", 0, 1, 1, 1) ; <--- 0011 invisible explorer <--- 0111 visible explorer _IELoadWait($oIE, $iGTimeToCeckTruck, $iGTimeOutTruck) Local $sLBodyHtl = _IEBodyReadHTML($oIE) Local $oBtns = $oIE.document.GetElementsByTagName("input") For $oBtn In $oBtns $id = String($oBtn.name()) ; ConsoleWrite($id & @CRLF) If $id = "city01" Then _IEAction($oBtn, "click") ; _IEFormElementSetValue($oBtn, $sUser) EndIf Next EndFunc ;==>_start Awesome that works. Thank you for your help. One last thing. I have a submit button and the _IEAction is not working: Here is a link: https://codepen.io/j1osu2006/pen/MWaEBmo #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <File.au3> #include <IE.au3> #include <Array.au3> #include <INet.au3> Global $iCont_truck = 0, $iGTimeToCeckTruck = 1000, $iGTimeOutTruck = 1000, $oIE _start() Func _start() If ProcessExists("iexplore.exe") Then ; Check if the internet esplorer process is running. ProcessClose("iexplore.exe") EndIf $oIE = _IECreate("https://codepen.io/j1osu2006/pen/MWaEBmo", 0, 1, 1, 1) ; <--- 0011 invisible explorer <--- 0111 visible explorer _IELoadWait($oIE, $iGTimeToCeckTruck, $iGTimeOutTruck) Local $sLBodyHtl = _IEBodyReadHTML($oIE) Local $oBtns = $oIE.document.GetElementsByTagName("input") For $oBtn In $oBtns $id = String($oBtn.name()) ; ConsoleWrite($id & @CRLF) If $id = "city01" Then _IEAction($oBtn, "click") ; _IEFormElementSetValue($oBtn, $sUser) Local $oBtnSubmit = $oIE.document.GetElementsByTagName("button") _IEAction($oBtnSubmit, "test") EndIf Next EndFunc ;==>_start I added: Local $oBtnSubmit = $oIE.document.GetElementsByTagName("button") _IEAction($oBtnSubmit, "test") "test" is the id of the button and its not working
goku200 Posted May 2, 2020 Author Posted May 2, 2020 I figured out the submit button part of it. I created an additional for loop: Local $oBtnss = $oIE.document.GetElementsByTagName("button") For $oBtnn In $oBtnss $id = String($oBtnn.id()) ; ConsoleWrite($id & @CRLF) If $id = "test" Then _IEAction($oBtnn, "click") ; _IEFormElementSetValue($oBtnn, $sUser) EndIf Next Thank you all for your help! 😃
goku200 Posted May 2, 2020 Author Posted May 2, 2020 2 minutes ago, goku200 said: I figured out the submit button part of it. I created an additional for loop: Local $oBtnss = $oIE.document.GetElementsByTagName("button") For $oBtnn In $oBtnss $id = String($oBtnn.id()) ; ConsoleWrite($id & @CRLF) If $id = "test" Then _IEAction($oBtnn, "click") ; _IEFormElementSetValue($oBtnn, $sUser) EndIf Next Thank you all for your help! 😃 Final Code is: expandcollapse popup#include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <File.au3> #include <IE.au3> #include <Array.au3> #include <INet.au3> Global $iCont_truck = 0, $iGTimeToCeckTruck = 1000, $iGTimeOutTruck = 1000, $oIE _start() Func _start() If ProcessExists("iexplore.exe") Then ; Check if the internet esplorer process is running. ProcessClose("iexplore.exe") EndIf $oIE = _IECreate("https://codepen.io/j1osu2006/pen/MWaEBmo", 0, 1, 1, 1) ; <--- 0011 invisible explorer <--- 0111 visible explorer _IELoadWait($oIE, $iGTimeToCeckTruck, $iGTimeOutTruck) Local $sLBodyHtl = _IEBodyReadHTML($oIE) Local $oBtns = $oIE.document.GetElementsByTagName("input") For $oBtn In $oBtns $id = String($oBtn.name()) ; ConsoleWrite($id & @CRLF) If $id = "city01" Then _IEAction($oBtn, "click") ; _IEFormElementSetValue($oBtn, $sUser) EndIf Next Local $oBtnss = $oIE.document.GetElementsByTagName("button") For $oBtnn In $oBtnss $id = String($oBtnn.id()) ; ConsoleWrite($id & @CRLF) If $id = "test" Then _IEAction($oBtnn, "click") ; _IEFormElementSetValue($oBtnn, $sUser) EndIf Next EndFunc ;==>_start
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