Abbie Posted April 7, 2017 Share Posted April 7, 2017 I use _IECreate to open router webui. I want to click the "AP" and "Wireless SSID". After login ,I use _IETagNameAllGetCollection to find "div". And show msgbox innerText information is "Username"、"Password". It look lick stay at login page. How do i do to find "AP" Obj ? Can someone help me ? My autoit code: #include <IE.au3> Local $oUser, $oPass, $oSubmit Local $oItem_AP Local $sUser = "admin" Local $sPass = "admin" Local $url = "192.168.50.1" Local $oIE = _IECreate($url, 1) _IELoadWait($oIE) $oInputs = _IETagNameGetCollection($oIE, "input") for $oInput in $oInputs if (Not isObj($oUser)) And $oInput.type = "text" And $oInput.name = "username" Then $oUser = $oInput if (Not isObj($oPass)) And $oInput.type = "password" And $oInput.name = "password" Then $oPass = $oInput if isObj($oUser) And isObj($oPass) then exitloop Next $oUser.value = $sUser $oPass.value = $sPass $oButtons = _IETagNameGetCollection($oIE, "button") for $oButton in $oButtons ;if (Not isObj($oSubmit)) And String($oButton.tabindex) = "3" Then $oSubmit = $oButton if (Not isObj($oSubmit)) And $oButton.classname = "submit_action" Then $oSubmit = $oButton if isObj($oSubmit) then exitloop Next _IEAction($oSubmit, "click") Sleep(5000) $oElements = _IETagNameAllGetCollection ($oIE) For $oElement In $oElements if $oElement.tagname = "div" then msgbox(0, "", $oElement.innerText) Next Login page: <form name="login_form" method="post"> <input name="func" type="hidden" value="login"> <div id="login_box"> <div style="font-weight: bold;">Login</div> <div> Username:<br> <input name="username" tabindex="1" class="text_box" type="text" autocapitalize="off"> </div> <div> Password:<br> <input name="password" tabindex="2" class="text_box" type="password" autocomplete="off"> </div> <button tabindex="3" class="submit_action" type="button">Login</button> <div class="smart_status" id="smart_status" style="display: none;"></div> <div class="company">Copyright © <span id="company_name_text">Pepwave</span>. All rights reserved.</div> </div> </form> Next page after login: <div class="top_menu_panel" style="text-align: left;"> <div class="top_menu_panel" style="width: 1024px;"> <div id="top_menu" style="width: 994px; float: left;"> <div class="top_menu_logo" style='background: url("connicon.cgi?type=top_logo") no-repeat;'> </div> <div class="menu_item menu_selected">Dashboard</div> <div class="menu_item menu_action">Network</div> <div class="menu_item menu_action">Advanced</div> <div class="menu_item menu_action">AP</div> <div class="menu_item menu_action">System</div> <div class="menu_item menu_end menu_action menu_status">Status</div> <div class="menu_item menu_end menu_apply">Apply Changes</div></div> </div> </div> Link to comment Share on other sites More sharing options...
Danp2 Posted April 7, 2017 Share Posted April 7, 2017 FWIW, your login code could likely be greatly simplified. Try this: $oForm = _IEFormGetObjByName($oIE, "login_form") $oUser = _IEFormElementGetObjByName($oForm, "username") $oPass = _IEFormElementGetObjByName($oForm, "password") _IEFormElementSetValue($oUser, $sUser) _IEFormElementSetValue($oPass, $sPass) _IEFormSubmit($oForm) Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Danp2 Posted April 7, 2017 Share Posted April 7, 2017 To find the correct next element, you could try something like: $oDivs = _IETagNameGetCollection($oIE, "div") For $oDiv In $oDivs If $oDiv.innerText = 'AP' Then _IEAction($oDiv, 'click') ExitLoop EndIf Next If that doesn't work, then I suggest that you save the entire HTML page to a file and post it here. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Abbie Posted April 10, 2017 Author Share Posted April 10, 2017 On 2017/4/7 at 7:06 PM, Danp2 said: To find the correct next element, you could try something like: $oDivs = _IETagNameGetCollection($oIE, "div") For $oDiv In $oDivs If $oDiv.innerText = 'AP' Then _IEAction($oDiv, 'click') ExitLoop EndIf Next If that doesn't work, then I suggest that you save the entire HTML page to a file and post it here. Thanks for your help. In this loop, The $oDiv.innerText is show "0". I try the other method : After login and staying at AP page (manual operation), then run loop. It still show "0". And no enable click event. HTML_1.txt HTML_2.txt Link to comment Share on other sites More sharing options...
Abbie Posted April 10, 2017 Author Share Posted April 10, 2017 (edited) 22 hours ago, Abbie said: Thanks for your help. In this loop, The $oDiv.innerText is show "0". I try the other method : After login and staying at AP page (manual operation), then run loop. It still show "0". And no enable click event. HTML_1.txt HTML_2.txt I find a viable method, but i don't know why ... After login, i use _IEDocReadHTML to check is at second page. And must be show one MsgBox (show anything). Then ReadHTML will be change to second page ... If no show one MsgBox, ReadHTML have been staying login page. expandcollapse popup#include <IE.au3> Run("WebUI_Login.exe", "", @SW_SHOWMAXIMIZED) WinWait("Web Admin | Welcome", "", 10) Local $Next = Call("WebUI_ReadHTML") While $Next = 0 Sleep(1000) $Next = Call("WebUI_ReadHTML") WEnd Call ("WebUI_SetWireless") Exit Func WebUI_ReadHTML() Local $oIE = _IEAttach("Web Admin","title") $source = _IEDocReadHTML ($oIE) MsgBox(0,"ReadHTML","Test") If StringInStr($source,"refresh") Then Return 1 Else Return 0 EndIf EndFunc Func WebUI_SetWireless() Local $oIE = _IEAttach("Web Admin","title") $oDivs = _IETagNameGetCollection($oIE, "div") For $oDiv In $oDivs If $oDiv.innerText = 'AP' Then _IEAction($oDiv, 'click') ExitLoop EndIf Next $olis = _IETagNameGetCollection($oIE, "li") For $oli In $olis If $oli.innerText = 'Wireless SSID' Then _IEAction($oli, 'click') ExitLoop EndIf Next EndFunc Edited April 11, 2017 by Abbie 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