mistersquirrle Posted May 4, 2017 Share Posted May 4, 2017 Hello, I'm trying to get some information on a webpage with IE.au3, however when I click a button on the page to load the content that I'm looking for, I can't seem to find that new information through any of the _IE functions. _IEDocReadHTML returns the original source, I can't find the table that it's in with _IETableGetCollection, _IEGetObjById can't find it, I tried attaching a new instance to the updated window, and reading it, still nothing. The process is load the page, click 'edit attached', and it populates a table on the right. This table is filled with a javascript function it looks like, and I can't get at that data. Here's what I have for code, just to test: #include-once #include <IE.au3> Global $sSite = "localhost/Account/IDX/AccountSpecificFeatures.aspx?id=242515" Global $oIE $oIE = _IECreate($sSite) ;$oEdit = _IEGetObjById($oIE, "rptrCustomFeatures_ctl02_lnkEditCustomFeature") _IEAction(_IEGetObjById($oIE, "rptrCustomFeatures_ctl00_lnkEditCustomFeature"), "click") _IELoadWait($oIE, 100, 5000) Sleep(1000) ;extra wait, just in case, it's quick to load though $sHTML = _IEDocReadHTML($oIE) MsgBox(0, '', $sHTML) ;~ ClipPut($sSource) _IEQuit($oIE) Exit I can't post a link to the page since it's internal, however I've attached a couple screenshots, and here's the property of the table that's resulted: <table cellspacing="0" rules="all" border="1" id="dgCurrentFeatures" style="border-collapse:collapse;"> So I should be able to find it by the ID, or it being a table, but neither are working. We ought not to misbehave, but we should look as though we could. Link to comment Share on other sites More sharing options...
Subz Posted May 5, 2017 Share Posted May 5, 2017 Can you try to use $oIE = _IEAttach("Title") after _IELoadWait? Link to comment Share on other sites More sharing options...
mistersquirrle Posted May 5, 2017 Author Share Posted May 5, 2017 (edited) 15 hours ago, Subz said: Can you try to use $oIE = _IEAttach("Title") after _IELoadWait? I did try that, doing something like this: Local $oIE2 = _IEAttach("IDX Feature Creator") Local $oCurrFeat = _IEGetObjById($oIE2, "dgCurrentFeatures") If @error Then MsgBox(0,'',':(' & @CRLF & @error,3) Local $oTable = _IETableGetCollection($oIE2, 0) Local $aTableData = _IETableWriteToArray($oTable) _ArrayDisplay($aTableData) But I still couldn't get it. That was after the _IELoadWait() and Sleep(1000) (and the additional table loads in ~100ms). Edit: Actually, I was able to get that to work, but only after having multiple instances of the IE window open. Check out the attached of 1 instance of the window, and then 3 instances where it actually found it (this is using the _IEAttach function after it's created and clicked onto). Edited May 5, 2017 by mistersquirrle Adding information We ought not to misbehave, but we should look as though we could. Link to comment Share on other sites More sharing options...
Subz Posted May 5, 2017 Share Posted May 5, 2017 Can you try something like: Sleep(3000) Local $oIE = _IEAttach("IDX Feature Creator") Local $aTableData Local $oTables = _IETableGetCollection($oIE) For $oTable In $oTables If $oTable.id = "dgCurrentFeatures" Then $aTableData = _IETableWriteToArray($oTable) ExitLoop EndIf Next _ArrayDisplay($aTableData) Link to comment Share on other sites More sharing options...
mistersquirrle Posted May 5, 2017 Author Share Posted May 5, 2017 8 minutes ago, Subz said: Can you try something like: I get the same type of thing as in my edit, no output when I run it, unless I leave up a couple of windows, and then it comes up after I have 3 windows up, check out the screenshot. Here's the code ATM: #include-once #include <IE.au3> #include <String.au3> #include <Array.au3> Global $sSite = "localhost/Account/IDX/AccountSpecificFeatures.aspx?id=242515" $oIE = _IECreate($sSite) $oEdit = _IEGetObjById($oIE, "rptrCustomFeatures_ctl00_lnkEditCustomFeature") _IEAction($oEdit, "click") _IELoadWait($oIE, 100, 5000) Sleep(3000) Local $oIE = _IEAttach("IDX Feature Creator") Local $aTableData Local $oTables = _IETableGetCollection($oIE) For $oTable In $oTables If $oTable.id = "dgCurrentFeatures" Then $aTableData = _IETableWriteToArray($oTable) ExitLoop EndIf Next _ArrayDisplay($aTableData) _IEQuit($oIE) Exit We ought not to misbehave, but we should look as though we could. Link to comment Share on other sites More sharing options...
mistersquirrle Posted May 9, 2017 Author Share Posted May 9, 2017 (edited) To add to this odd behavior, I also cannot close the IE window with _IEQuit($oIE) after its clicked on the 'edit attached' option. For reference I tried this: #include <IE.au3> $oIE = _IECreate() Sleep(2000) _IEQuit($oIE) Exit That worked just fine. I then tried it with my URL, and that closed fine. Tried it by opening the URL, attaching with _IEAttach() and then closing the new handle, that worked fine. It's only after it clicks 'edit attached' that when I call _IEQuit() it cannot actually close the window. There's no error when I call _IEQuit(), it just doesn't do it. I then tried this: #include-once #include <IE.au3> #include <Array.au3> Global $sSite = "http://localhost/Account/IDX/AccountSpecificFeatures.aspx?id=242515" $i = 0 $oIE = _IECreate($sSite) $oEdit = _IEGetObjById($oIE, "rptrCustomFeatures_ctl00_lnkEditCustomFeature") _IEAction($oEdit, "click") _IELoadWait($oIE, 100, 5000) Sleep(1000) While 1 $i += 1 ToolTip($i) Local $oIE2 = _IEAttach("IDX Feature Creator") Local $aTableData Local $oTables = _IETableGetCollection($oIE2) For $oTable In $oTables If $oTable.id = "dgCurrentFeatures" Then $aTableData = _IETableWriteToArray($oTable) ExitLoop EndIf Next _ArrayDisplay($aTableData) Sleep(10) WEnd _IEQuit($oIE2) Exit So basically, looping through attaching to a window, getting the tables, and printing it. When I run it without another window up, it goes through ~276 loops, then closes with this error: "C:\Program Files (x86)\AutoIt3\Include\IE.au3" (1506) : ==> The requested action with this object has failed.: Return SetError($_IESTATUS_Success, $oObject.document.GetElementsByTagName("table").length, $oObject.document.GetElementsByTagName("table")) Return SetError($_IESTATUS_Success, $oObject.document^ ERROR If I run it with an existing window (so it runs with two up), it sometimes gets the table, sometimes doesn't. It's pretty random, and when it does get it, it will keep looping anywhere from another 4-30 times in the tests I did, before giving the above error. With two existing windows up (so three while it's running), it gets it on the first loop. I'm lost here on the behavior of IE when it clicks this link/button, and why it can't get the data with 1 window, but it can with 3. Any suggestions? EDIT: I tried running this with: $oIE = _IECreate($sSite,0,0,1,0), to make the window invisible (more to test if it would properly close with _IEQuit()) and it looks like that I'm able to reliably get the table now, and _IEQuit works without a problem. Any explanation for that? Edited May 9, 2017 by mistersquirrle Additional details We ought not to misbehave, but we should look as though we could. 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