rj_hunter Posted February 20, 2020 Share Posted February 20, 2020 I am new to AutoIT and struggling with a simple script. What I need help with is as follows: Open IE --> Particular URL --> Select Item --> Click on Go button. Simple enough but the selection box (See DSPageLoad.jpg - Google Inspector) doesn't seem to a form or part of a form, and most of the tutorials focus around automated form inputs. 1. Google Inspect - show the "selection box" as follows: <select id="ddlplantNo" data-val="true" data-val-number="The field signageNo must be a number." data-val-required="The signageNo field is required." name="signageNo"><option value="1">Test1</option> <option value="2">Test 2</option> <option value="3">Test 3</option> </select> 2. Google Inspect - shows the GO button as follows: <span class="ui-button-text">GO</span> The script I have so far and it working is as follows: SCRIPT: #include <IE.au3> Global $oIE = _IECreate ("http://signage.maritimepaper.com/signageappcorr") Link to comment Share on other sites More sharing options...
Danp2 Posted February 20, 2020 Share Posted February 20, 2020 Based on the information you've provided, you should be able to use _IEGetObjById to obtain a reference to the select element. Then use this object reference with _IEFormElementOptionSelect to choose one of the element's options. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
rj_hunter Posted February 20, 2020 Author Share Posted February 20, 2020 Thanks Danp2 for your help above. The following is working great for me but I am struggling to script the the last piece and that is clicking on the GO button, see my script below. SCRIPT: #include <IE.au3> Call ("selection") Func selection () Global $oIE = _IECreate ("http://signage.maritimepaper.com/signageappcorr") Local $selectid = _IEGetObjByName ($oIE, "signageNo") _IEFormElementOptionSelect ($selectid, "3") EndFunc Link to comment Share on other sites More sharing options...
rj_hunter Posted February 20, 2020 Author Share Posted February 20, 2020 I am trying the following script and its not working, see error --> IE.au3 T3.0-2 Warning from function _IEGetObjByName, $_IESTATUS_NoMatch (Name: GO, Index: 0) --> IE.au3 T3.0-2 Error from function _IEAction(click), $_IESTATUS_InvalidDataType SCRIPT: #include <IE.au3> Call ("selection") Func selection () Global $oIE = _IECreate ("http://signage.maritimepaper.com/signageappcorr") Local $selectid = _IEGetObjByName ($oIE, "signageNo") Local $button = _IEGetObjByName ($oIE, "GO") _IEFormElementOptionSelect ($selectid, "3") _IEAction ($button,"click") EndFunc Link to comment Share on other sites More sharing options...
Nine Posted February 20, 2020 Share Posted February 20, 2020 The button has no name, you will need to use _IETagNameGetCollection and loop thru the object until you find the one having innerText = "GO". Next time you post code, please use this tool. ps. do not use call unless it is necessary, just use Selection () directly “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Danp2 Posted February 20, 2020 Share Posted February 20, 2020 The span element doesn't have a name or id attribute, so you can't use _IEGetObjByName or _IEGetObjById. A few options -- Look to see if this span is actually inside a link (<a> element). If so, you can likely use _IELinkClickByText If not, then you can use _IETagNameGetCollection to get a collection of span elements and then loop through the collection to find the desired one. This has been demonstrated numerous times on the forum, so you should be able to find an example using the forum search feature Lastly, you may be able to find a nearby element with either an ID or name. If so, you can possibly use it to locate the desired span element A couple of additional pointers -- You don't need to use Call. Just execute the function like this -- #include <IE.au3> selection() Notice how I posted the code above? You can do the same by using the code button (looks like <>) in the toolbar. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Danp2 Posted February 20, 2020 Share Posted February 20, 2020 @Nine Grape minds 🤣 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Nine Posted February 20, 2020 Share Posted February 20, 2020 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
rj_hunter Posted February 20, 2020 Author Share Posted February 20, 2020 #include <IE.au3> selection() Func selection () Global $oIE = _IECreate ("http://signage.maritimepaper.com/signageappcorr") Local $selectid = _IEGetObjByName ($oIE, "signageNo") _IEFormElementOptionSelect ($selectid, "3") EndFunc clickobjbyclass($oIE, 'ui-button-text-only') Func clickobjbyclass(ByRef $oIE, $class) $tags = $oIE.document.GetElementsByTagName('button') For $tag In $tags $class = $tag.GetAttribute('class') If String($class) = $class Then Return _IEAction($tag, 'click') EndIf Next Return False EndFunc Firstly Thanks for all the help, I think we are almost there. The above scripts works fine until it runs the button piece. When the button script runs I am left with a browser with no info, it just blank. see element inspectector for the button called "GO": <button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false" type="button"> <span class="ui-button-text">GO</span></button> Note that I tried _IELinkClickByText and that didn't work for me. Link to comment Share on other sites More sharing options...
Nine Posted February 20, 2020 Share Posted February 20, 2020 First you are reusing the $class as a parameter AND as a variable to capture the class attribute. There should be 2 separate variables. Second do not mix your main code in between functions. It will get infernal to debug after awhile when the program gets bigger. Put all your main code at the beginning of the script. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
rj_hunter Posted February 21, 2020 Author Share Posted February 21, 2020 Can you be more specific I am new to scripting, can you write the code for me? Link to comment Share on other sites More sharing options...
Danp2 Posted February 21, 2020 Share Posted February 21, 2020 Pretty sure he means like this -- #include <IE.au3> selection() clickobjbyclass($oIE, 'ui-button-text-only') ; *********** Moved from below Func selection () Global $oIE = _IECreate ("http://signage.maritimepaper.com/signageappcorr") Local $selectid = _IEGetObjByName ($oIE, "signageNo") _IEFormElementOptionSelect ($selectid, "3") EndFunc Func clickobjbyclass(ByRef $oIE, $desiredclass) ; *********** Renamed parameter to prevent clash $tags = $oIE.document.GetElementsByTagName('button') For $tag In $tags $class = $tag.GetAttribute('class') If String($class) = $desiredclass Then Return _IEAction($tag, 'click') EndIf Next Return False EndFunc Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
rj_hunter Posted February 21, 2020 Author Share Posted February 21, 2020 Thanks Danp2 for the explanation, the code looks much neater and easier to understand. I tried the above code and its still not working. Could you run the following code for me and let me know what I am missing. URL is open to the public so it should resolve for you. #include <IE.au3> selection() clickobjbyclass($oIE, 'ui-button-text-only') ; *********** Moved from below clickobjbyclass2($oIE, 'ui-button-text-only') Func selection () Global $oIE = _IECreate ("http://signage.maritimepaper.com:8042/signageappcorr") Local $selectid = _IEGetObjByName ($oIE, "signageNo") _IEFormElementOptionSelect ($selectid, "3") EndFunc Func clickobjbyclass(ByRef $oIE, $desiredclass) ; *********** Renamed parameter to prevent clash $tags = $oIE.document.GetElementsByTagName('button') For $tag In $tags $class = $tag.GetAttribute('class') If String($class) = $desiredclass Then Return _IEAction($tag, 'click') EndIf Next Return False EndFunc Link to comment Share on other sites More sharing options...
Nine Posted February 21, 2020 Share Posted February 21, 2020 (edited) Try this : #include <Constants.au3> #include <IE.au3> Global $oIE selection() clickobjbyText($oIE, 'GO') Func selection () $oIE = _IECreate ("http://signage.maritimepaper.com:8042/signageappcorr") Local $selectid = _IEGetObjByName ($oIE, "signageNo") _IEFormElementOptionSelect ($selectid, "3") EndFunc Func clickobjbyText(ByRef $oIE, $desiredText) Local $tags = $oIE.document.GetElementsByTagName('span') For $tag In $tags If $tag.innerText = $desiredText Then ConsoleWrite ("found" & @CRLF) Return _IEAction($tag, 'click') EndIf Next Return False EndFunc Edited February 21, 2020 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
rj_hunter Posted February 21, 2020 Author Share Posted February 21, 2020 Thanks for all the help works great. 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