Jump to content

How to get the source after executing javascript


Recommended Posts

I'm trying to get the HTML code after executing javascript in IE. Here is my code.

$url = "http://example.com"
$oIE = _IECreate($url)
Sleep(3000) ;waiting for executing javascript. But useless.
$oFrame = _IEFrameGetCollection($oIE, 0)
$sCode &= _IEPropertyGet($oFrame, "innerhtml") & @CRLF

Then, I get this error.

"C:\Program Files (x86)\AutoIt3\Include\IE.au3" (2308) : ==> The requested action with this object has failed.:
$oTemp = $oObject.document.body
$oTemp = $oObject^ ERROR

After executing javascript, when I view source in IE, there are HTML code like below.

<html>
<head>
...
</head>
<body>
...
</body>
</html>

What should I do?

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By goku200
      I'm having an issue with my html paginated table. The script work as expected. It reads the html table and clicks on the Download button. However when it clicks on the next page its not iterating the items. instead it goes to the next URL from the spreadsheet and then iterates through the html table clicking the Download button and so on. Not sure why its doing that. I want it to click the next page and then continue iterating then after it has reached the end of the pagination go to the next url in the spreadsheet and repeat the process. Below is my script. Any help is appreciated ūüôā
      HTML Table:
      <!doctype html> <html> <head> <meta charset="utf-8"> <title>Test</title> </head> <body> <span style="font-weight:bold; font-size:13px">12345</span> <table width="100%" cellspacing="0" cellpadding="0" border="0"> <tbody><tr> <td> <table width="100%" cellspacing="1" cellpadding="2" border="0"> <tbody> <tr> <td class="test">ID</td> <td class="test" width="100%" nowrap=""> Name</td> <td class="test" nowrap="">Test1 Name</td> <td class="test" nowrap="">Test Date</td> <td class="test" nowrap="">Test Default</td> <td class="test" nowrap="">Test Status</td> <td class="test" nowrap="">Test Format</td> <td class="test" colspan="4">Actions&nbsp;</td> </tr> <tr> <td class="test" align="center">1</td> <td class="test">Test1</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">1/19/2022</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download1">Download</a></td> </tr> <tr> <td class="test" align="center">2</td> <td class="test">Test2</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">1/19/2022</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download2">Download</a></td> </tr> <tr> <td class="test" align="center">3</td> <td class="test">Test3</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">1/19/2022</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download3">Download</a></td> </tr> <tr> <td class="test" align="center">4</td> <td class="test">Test4</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">1/19/2022 </td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download4">Download</a></td> </tr> <tr> <td class="test" align="center">5</td> <td class="test">Test5</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">1/19/2022</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download5">Download</a></td> </tr> <tr> <td class="test" align="center">6</td> <td class="test">Test6</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">1/19/2022</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download6">Download</a></td> </tr> <tr> <td class="test" align="center">7</td> <td class="test">Test7</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">1/19/2022</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download7">Download</a></td> </tr> <tr> <td class="test" align="center">8</td> <td class="test">Test8</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">1/19/2022</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download8">Download</a></td> </tr> <tr> <td class="test" align="center">9</td> <td class="test">Test9</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">1/7/2022</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download9">Download</a></td> </tr> <tr> <td class="test" align="center">10</td> <td class="test">Test10</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">12/8/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download10">Download</a></td> </tr> <tr> <td class="test" align="center">11</td> <td class="test">Test11</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">12/5/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download11">Download</a></td> </tr> <tr> <td class="test" align="center">12</td> <td class="test">Test12</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">12/5/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download12">Download</a></td> </tr> <tr> <td class="test" align="center">13</td> <td class="test">Test13</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">12/5/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download13">Download</a></td> </tr> <tr> <td class="test" align="center">14</td> <td class="test">Test14</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">11/29/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download14">Download</a></td> </tr> <tr> <td class="test" align="center">15</td> <td class="test">Test15</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">11/29/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download15">Download</a></td> </tr> <tr> <td class="test" align="center">16</td> <td class="test">Test16</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">11/29/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download16">Download</a></td> </tr> <tr> <td class="test" align="center">17</td> <td class="test">Test17</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">11/29/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download17">Download</a></td> </tr> <tr> <td class="test" align="center">18</td> <td class="test">Test18</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">11/29/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download18">Download</a></td> </tr> <tr> <td class="test" align="center">19</td> <td class="test">Test19</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">11/29/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download19">Download</a></td> </tr> <tr> <td class="test" align="center">20</td> <td class="test">Test20</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">11/29/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download20">Download</a></td> </tr> <tr> <td class="test" align="center">21</td> <td class="test">Test21</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">11/29/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download21">Download</a></td> </tr> <tr> <td class="test" align="center">22</td> <td class="test">Test22</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">11/29/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download22">Download</a></td> </tr> <tr> <td class="test" align="center">23</td> <td class="test">Test23</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">11/29/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download23">Download</a></td> </tr> <tr> <td class="test" align="center">24</td> <td class="test">Test24</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">11/29/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download24">Download</a></td> </tr> <tr> <td class="test" align="center">25</td> <td class="test">Test25</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">11/29/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download25">Download</a></td> </tr> </tbody></table> </td></tr> </tbody></table> <table cellspacing="1" cellpadding="3" border="0"> <tbody><tr> <td valign="middle"> </td> <td valign="middle"> <select name="next"> <option value="1" selected="">Page 1 of 7 </option><option value="2">Page 2 of 7 </option><option value="3">Page 3 of 7 </option><option value="4">Page 4 of 7 </option><option value="5">Page 5 of 7 </option><option value="6">Page 6 of 7 </option><option value="7">Page 7 of 7 </option></select> </td> <td valign="middle"> <a href="Next">Next</a> </td> </tr> </tbody></table> </body> </html> Autoit script
      #Include "wd_core.au3" #Include "wd_helper.au3" #Include "WinHttp.au3" #include <MsgBoxConstants.au3> #include <File.au3> #include <AutoItConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <Excel.au3> Local $sDesiredCapabilities, $sSession SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_LoadWait($sSession) Sleep(5000) _WD_LoadWait($sSession) Sleep(5000) _WD_Navigate($sSession, '') _WD_LoadWait($sSession) _WD_NewTab($sSession) $ArticleWindow = _WD_Window($sSession, 'window', '') _WD_LoadWait($sSession) sleep(5000) _ExcelFunction() Func _ExcelFunction() Local $oAppl = _Excel_Open() Local $sWorkbook = "C:\Users\<username here>\Downloads\table.xlsx" Local $oWorkbook = _Excel_BookOpen($oAppl, $sWorkbook) Local $aArray2 = _Excel_RangeRead($oWorkbook,Default,$oWorkbook.ActiveSheet.Usedrange.Columns("A:A")) For $i = 0 To UBound($aArray2) - 1 ;Skip from reading header columns Local $Skipline = 1 ;0==> first line Local $temprf $temprf &= $aArray2[$i] If @error Then ContinueLoop If $i < $Skipline Then ContinueLoop _WD_Window($sSession, 'Switch', '{"handle":"' & $ArticleWindow & '"}') sleep(500) _WD_Navigate($sSession, $aArray2[$i]) _WD_LoadWait($sSession) Sleep(2000) htmlTable() Next EndFunc Func htmlTable() $sTable = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//html/body/table[1]/tbody/tr/td/table") _WD_HighlightElement($sSession, $sTable, 2) _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//html/body/table[1]/tbody/tr/td/table/tbody") Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//html/body/table[1]/tbody/tr/td/table/tbody") Local $aArray1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, ".//td[8]/a", $sElement, True) For $i = 0 to UBound($aArray1) - 1 $aArray1[$i] = _WD_ElementAction($sSession, $aArray1[$i], 'text') Next _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//html/body/table[1]/tbody/tr/td/table/tbody") Local $sElement1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//html/body/table[1]/tbody/tr/td/table/tbody") Local $aArray11 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, ".//td[1]", $sElement1, True) For $j = 0 to UBound($aArray11) - 1 ;Skip from reading header columns Local $Skipline = 0 ;0==> first line Local $temprf $temprf &= $aArray11[$j] If @error Then ContinueLoop If $j < $Skipline Then ContinueLoop $aArray11[$j] = _WD_ElementAction($sSession, $aArray11[$j], 'text') Next ;Finds the ID and places it in a variable Local $sElement10 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//html/body/span") $sValue = _WD_ElementAction($sSession, $sElement10, 'text') ;Finds the ID and places it in a variable Local $sElement11 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, ".//td[1]") $sValue2 = _WD_ElementAction($sSession, $sElement11, 'text') For $i = 0 to UBound($aArray1) - 1 ;Find the table of all the IDs $sButton1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//html/body/table[1]/tbody/tr/td/table") _WD_HighlightElement($sSession, $sButton1, 2) _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//html/body/table[1]/tbody/tr/td/table/tbody") Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//html/body/table[1]/tbody/tr/td/table/tbody") Local $aArray1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, ".//td[8]/a", $sElement, True) _WD_HighlightElement($sSession, $aArray1, 2) $links = _WD_ElementAction($sSession, $aArray1[$i], 'click') Sleep(2000) FileMove('C:\Users\<username here>\Downloads\*.html', 'C:\Users\<username here>\Downloads\' & $sValue & "_r" & $aArray11[$i] & '.htm', 1) Next ;Click on Next Page Local $next = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//html/body/table[2]/tbody/tr/td[3]/a") _WD_ElementAction($sSession, $next, 'click') Sleep(2000) EndFunc _WD_Shutdown() Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"debuggerAddress": "localhost:9222"} {"w3c": true, "args":["start-maximized","disable-infobars"]}}}}' EndFunc  
    • By Steviep
      Hi all,
      I've been using the following code for many years for the sole purpose of tracking my app usage via Google Analytics:
      ;GOOGLE ANALYTICS $AppStatsName = @ScriptName $GA = _IECreate("https://mywebserver/apps/stats/" & $AppStatsName & ".html", 0, 0, 0, 0) The app simply calls a blank .html page on my webserver which only contains the GA tracking code.
      The $iVisible parameter is set to "0" in my case, which means the IE browser is invisible to the user.
      I noticed in Windows 11, the URL is called in the Edge browser and is not invisible.
      So, I wonder if anyone out there has any suggestions on calling a URL invisibly on any operating system?
      Thanks!
    • By Chimp
      This script is an alternative (improvement) to the script published at this link (www.autoitscript.com/forum/topic/186225-interesting-effect-with-transparency). In that post a flash animation was used and therefore you need the flash player to work, while here only javascript is used.
      Here, too, the aim is to show an interesting effect that can be obtained by exploiting transparency, but can also be used as it is just for fun.
      The animation consists of some fish wandering around the screen. You can continue working on the computer by letting them swim.
      The javascript source was not written by me, but I got it from this link: https://github.com/lrusso/Aquarium. I shrunk it down a bit and tweaked it so that fish can swim across the entire screen even with different sized monitors.
      The fish images and html and javascript sources have been bundled into a single "monolithic" AutoIt script, so it's easier to run.
      I hope you find it relaxing.
      Have fun
      fishMonolitic.zip
    • By Hermes
      Hi, I have a site that has the following elements below: 
      <div>More element here</div> <div>More element here</div> <div>More element here</div> When I do this in Auto It:
      Local $oSelectDiv = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "div") _WD_HighlightElement($sSession, $oSelectDiv, 1) I also tried to add [3], but it doesnt seems to work:
      Local $oSelectDiv = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "div[3]") _WD_HighlightElement($sSession, $oSelectDiv, 1) It always highlight the first one, but I am trying to highlight the 3rd in the list. Is there anyway to select the 3rd div without having to add any class/id in the divs, and without using XPATH? The structure of the elements in that site were built that way.
    • By Pured
      I am looking to create a script which refreshes/reads a webpage every few seconds. My goal is to see if the page has changed, then I will send myself a notification that the webpage has been updated.
       
      However, rather than downloading the entire webpage every single time, is there a way to check when the webpage last updated?
       
      If not, is there away to partially download/read html source until a specific tag is hit?
       
      Goal: I would like to increase my poll rate and not excessively waste data.
×
×
  • Create New...