Faalamva

[SOLVED] [IE.au3] How to "refresh" elements coordinates after the first use of _IECreate ?

11 posts in this topic

#1 ·  Posted (edited)

Hi,

I'm using the IE.au3 library to parse elements in a webpage and get their (x,y) coordinates.

Main commands I'm using are :         

$oIE = _IECreate($myWebPage)

$oElements = _IETagNameGetCollection($oIE, "label")

$windowleft = $oIE.document.parentwindow.screenLeft
$windowtop = $oIE.document.parentwindow.screenTop

$oElementPosX = $windowleft + _IEfindPosX($oElement)
$oElementPosY = $windowtop + _IEfindPosY($oElement)

Now things become a bit tricky when i simulate a scroll in my webpage :

$oIE.document.parentwindow.scroll(0, $myScrollY)

Because once this is done, the coordinates of the elements are still what they were before the scroll.

I can manage this problem by keeping track of the number of pixels I have scrolled, and compute the new "real" ($oElementPosX, $oElementPosY).

But I'm pretty sure there's a more efficient / more elegant way to do it.

What's more in some situations, when I click some controls in the webpage, the webpage adds new elements and shifts the controls below by a random number of pixel, so my workaround can't be used...

So here's my question : Is there a way to "refresh" the calculation of label coordinates ($oElementPosX, $oElementPosY) after a scroll ?

Thank you !

EDIT : I forgot to post the _IEfindPosX and _IEfindPosY functions (found somewhere on this forum) :

Func _IEfindPosX($o_object)
    Local $curleft = 0
    Local $parent = $o_object
    If IsObj($parent) Then
        While IsObj($parent)
            $curleft += $parent.offsetLeft
            $parent = $parent.offsetParent
        WEnd
    Else
        Local $objx = $o_object.x
        If IsObj($objx) Then $curleft += $objx
    EndIf
    Return $curleft
EndFunc

Func _IEfindPosY($o_object)
    Local $curtop = 0
    Local $parent = $o_object
    If IsObj($parent) Then
        While IsObj($parent)
            $curtop += $parent.offsetTop
            $parent = $parent.offsetParent
        WEnd
    Else
        Local $objy = $o_object.y
        If IsObj($objy) Then $curtop += $objy
    EndIf
    Return $curtop
EndFunc

 

Edited by Faalamva

Share this post


Link to post
Share on other sites



26 minutes ago, l3ill said:

Cant you just rerun the function you used to find them the first time ?

Thank you for your answer, unfortunately, I've already tried and it doesn't work.

Here is a full example to illustrate my problem. Just copy/paste and run it and you'll understand what I'm trying to achieve.

 

#include <IE.au3>

; ----------------------------------------------------------------------
; Main
; ----------------------------------------------------------------------

$oIE = _IECreate("http://www.york.ac.uk/teaching/cws/wws/webpage1.html")
WinSetState("","",@SW_MAXIMIZE)

$windowleft = $oIE.document.parentwindow.screenLeft
$windowtop = $oIE.document.parentwindow.screenTop
$oElements = _IETagNameAllGetCollection($oIE)

For $oElement In $oElements
    If $oElement.innerText = "EXERCISE" Then
        $oElementPosX = $windowleft + _IEfindPosX($oElement)
        $oElementPosY = $windowtop + _IEfindPosY($oElement)
        MsgBox(0, "", "Mouse will be moved to ""EXERCISE"" position")
        MouseMove($oElementPosX, $oElementPosY)
    EndIf
Next

MsgBox(0, "", "Let's scroll the webpage 200 pixels down")
$oIE.document.parentwindow.scroll(0, 200)

; Trying to "refresh the elements positions" --> it doesn't work
$oElements = _IETagNameAllGetCollection($oIE)

For $oElement In $oElements
    If $oElement.innerText = "EXERCISE" Then
        $oElementPosX = $windowleft + _IEfindPosX($oElement)
        $oElementPosY = $windowtop + _IEfindPosY($oElement)
        MsgBox(0, "", "Mouse will be moved again to ""EXERCISE"" position")
        MouseMove($oElementPosX, $oElementPosY)
    EndIf
Next

MsgBox(0, "", "Positions of webpage elements haven't been refreshed, the mouse was moved to the former EXERCISE position...")

; ----------------------------------------------------------------------
; Functions
; ----------------------------------------------------------------------

Func _IEfindPosX($o_object)
    Local $curleft = 0
    Local $parent = $o_object
    If IsObj($parent) Then
        While IsObj($parent)
            $curleft += $parent.offsetLeft
            $parent = $parent.offsetParent
        WEnd
    Else
        Local $objx = $o_object.x
        If IsObj($objx) Then $curleft += $objx
    EndIf
    Return $curleft
EndFunc

Func _IEfindPosY($o_object)
    Local $curtop = 0
    Local $parent = $o_object
    If IsObj($parent) Then
        While IsObj($parent)
            $curtop += $parent.offsetTop
            $parent = $parent.offsetParent
        WEnd
    Else
        Local $objy = $o_object.y
        If IsObj($objy) Then $curtop += $objy
    EndIf
    Return $curtop
EndFunc

 

Share this post


Link to post
Share on other sites

Sorry, no answers just some info; I added some error checking and it would seem that your If statement is not working correctly.

Spoiler
$oIE = _IECreate("http://www.york.ac.uk/teaching/cws/wws/webpage1.html")
WinSetState("", "", @SW_MAXIMIZE)

Local $windowleft = $oIE.document.parentwindow.screenLeft
Local $windowtop = $oIE.document.parentwindow.screenTop
Local $oElements = _IETagNameAllGetCollection($oIE)

For $oElement In $oElements
    If $oElement.innerText = "EXERCISE" Then
        MsgBox(0, "Success", "EXERCISE found in 'InnerText'")
        Local $oElementPosX = $windowleft + _IEfindPosX($oElement)
        Local $oElementPosY = $windowtop + _IEfindPosY($oElement)
        ConsoleWrite("$oElementPosX = " & $oElementPosX & @CRLF)
        ConsoleWrite("$oElementPosY = " & $oElementPosY & @CRLF)
        MsgBox(0, "", "Mouse will be moved to ""EXERCISE"" position")
        MouseMove($oElementPosX, $oElementPosY)
    Else
        MsgBox(0, "error", "Something went wrong here...")
    EndIf
Next

MsgBox(0, "", "Let's scroll the webpage 200 pixels down")
$oIE.document.parentwindow.scroll(0, 200)

; Trying to "refresh the elements positions" --> it doesn't work
$oElements = _IETagNameAllGetCollection($oIE)

For $oElement In $oElements
    If $oElement.innerText = "EXERCISE" Then
        MsgBox(0, "Success", "EXERCISE found in 'InnerText'")
        Local $oElementPosX = $windowleft + _IEfindPosX($oElement)
        Local $oElementPosY = $windowtop + _IEfindPosY($oElement)
        ConsoleWrite("$oElementPosX = " & $oElementPosX & @CRLF)
        ConsoleWrite("$oElementPosY = " & $oElementPosY & @CRLF)
        MsgBox(0, "", "Mouse will be moved again to ""EXERCISE"" position")
        MouseMove($oElementPosX, $oElementPosY)
    Else
        MsgBox(0, "error", "Something went wrong here...")
    EndIf
Next
MsgBox(0, "", "Positions of webpage elements haven't been refreshed, the mouse was moved to the former EXERCISE position...")

You should take a closer look at how your Functions are being called. It also good practice to use Local or Global when defining variables.

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Your example won't work, it will display

"Something went wrong here..."

everytime the element checked isn't "EXERCISE".

Please remember that this is just an example I wrote in a few minutes to illustrate the case, it may not be state-of-the-art of course.

But it's working as a standalone program, just copy/paste and run it to see by yourself.

Let's stick to the topic please :)

Edited by Faalamva

Share this post


Link to post
Share on other sites

Understood..

A simple test reveals that your website does not have the .innerText element you are trying to use:

From the Help File:

#include <IE.au3>
#include <MsgBoxConstants.au3>

;~ Local $oIE = _IE_Example("basic")
$oIE = _IECreate("http://www.york.ac.uk/teaching/cws/wws/webpage1.html")

Local $oElements = _IETagNameAllGetCollection($oIE)
For $oElement In $oElements
    If $oElement.id Then MsgBox($MB_SYSTEMMODAL, "Element Info", "Tagname: " & $oElement.tagname & @CRLF & "id: " & $oElement.id & @CRLF & "innerText: " & $oElement.innerText)
Next

_IEQuit($oIE)

Without the error checking your script is finding mouse coordinates one time but the rest of the code is skipping through (aka: not working)

If you have access to the code from your page I would suggest giving the 'EXERCISE' header (or whatever) its own .id and then write your code to pick up on that element.


<h4 id="myHeader">Exercise</h4>

My $0.02 ...

Good luck o:)

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

#include <IE.au3>
#include <MsgBoxConstants.au3>

;~ Local $oIE = _IE_Example("basic")
$oIE = _IECreate("http://www.york.ac.uk/teaching/cws/wws/webpage1.html")

Local $oElements = _IETagNameAllGetCollection($oIE)
For $oElement In $oElements
    ConsoleWrite("Tagname: " & $oElement.tagname & @CRLF & " id: " & $oElement.id & @CRLF & " innerText: " & $oElement.innerText & @CRLF)
Next

_IEQuit($oIE)

Result in console :

Quote

...

Tagname: H4
 id:
 innerText: EXERCISE

...

We're still drifting away from topic... :(

Edited by Faalamva

Share this post


Link to post
Share on other sites

No, your right. Never mind all that.

It is more difficult than I had hoped. Your coordinate variables are staying in memory for some reason and zeroing them out didn't work.

Sorry couldn't help.

...all the smart people have gone to bed...:P

might have to wait until tomorrow :'(

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

... try this:

#include <IE.au3>
; ----------------------------------------------------------------------
; Main
; ----------------------------------------------------------------------
$oIE = _IECreate("http://www.york.ac.uk/teaching/cws/wws/webpage1.html")
WinSetState("", "", @SW_MAXIMIZE)

$oElement = _IETagNameGetCollection($oIE, 'H4', 0)
MouseMove($oElement.getBoundingClientRect().left + $oIE.document.parentwindow.screenleft, $oElement.getBoundingClientRect().top + $oIE.document.parentwindow.screentop)

MsgBox(0, "", "Let's scroll the webpage 200 pixels down", 2)
$oIE.document.parentwindow.scroll(0, 200)
MouseMove($oElement.getBoundingClientRect().left + $oIE.document.parentwindow.screenleft, $oElement.getBoundingClientRect().top + $oIE.document.parentwindow.screentop)

MsgBox(0, "", "caught!", 2)
$oElement.style.setAttribute('border', '5px solid red') ; draw a red border (just for fun)

 

Edited by Chimp
1 person likes this

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Very interesting Chimp, it seems we're heading in the right direction :lol: !

EDIT : I managed to adapt your code to get exactly what I need (i.e. using displayed labels instead of "H4") :

#include <IE.au3>

$oIE = _IECreate("http://www.york.ac.uk/teaching/cws/wws/webpage1.html")
WinSetState("", "", @SW_MAXIMIZE)

Local $myElement
$oElements = _IETagNameAllGetCollection($oIE)
For $oElement In $oElements
    If $oElement.innerText = "EXERCISE" Then $myElement = $oElement
Next

MsgBox(0, "", "Let's locate EXERCISE")
MouseMove($myElement.getBoundingClientRect().left + $oIE.document.parentwindow.screenleft, $myElement.getBoundingClientRect().top + $oIE.document.parentwindow.screentop)
MsgBox(0, "", "Let's scroll the webpage 200 pixels down")
$oIE.document.parentwindow.scroll(0, 200)
MsgBox(0, "", "Let's locate EXERCISE again")
MouseMove($myElement.getBoundingClientRect().left + $oIE.document.parentwindow.screenleft, $myElement.getBoundingClientRect().top + $oIE.document.parentwindow.screentop)

EDIT 2 : Tested "for real" in dynamic webpages. Works perfectly, and much simpler/shorter than the original code.

Case solved, thank you ! :)

Edited by Faalamva

Share this post


Link to post
Share on other sites
2 hours ago, Faalamva said:

......

Case solved, thank you ! :)

You are welcome... ;)


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


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

  • Similar Content

    • Ubermensch
      By Ubermensch
      Hello guys,
      I am new here in our forum. I do have a little knowledge about AutoIt. I hope you could assist me. 
      I am currently working on a project. I want to try to create an automated time tracking tool.
      This is how I want to function our time tracking tool.
      Start time when the IE "get" button  is clicked. End time when either "Next Step", "Save" or "Cancel" button is clicked. All the values in the available fields will be stored in an Excel I already have codes for the time tracking part, unfortunately, I cannot proceed since I am encountering an error for detecting the buttons in IE.
      Here is my initial code for detecting the IE button.
      #include <IE.au3> #include <MsgBoxConstants.au3> Local $oIE = _IECreate("C:\Users\april\Documents\Logo\JRB\AutoIt\AutoBOT\AWD10\sampleAWD10.html") Local $oLastName = _IEFormElementGetObjByName($oIE, "Text4") Local $oGetItem = _IEFormElementGetObjByName($oIE, "getitem") _IELoadWait($oIE) _IEAction($oGetItem, "click") MsgBox($MB_SYSTEMMODAL, "Form Element Value", _IEFormElementGetValue($oGetItem)) Here is the console output.
      >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\april\Documents\Logo\JRB\AutoIt\AutoBOT\AWD10\AWD10.au3" /UserParams +>23:22:20 Starting AutoIt3Wrapper v.17.224.935.0 SciTE v.3.7.3.0 Keyboard:00000409 OS:WIN_10/ CPU:X64 OS:X64 Environment(Language:0409) CodePage:0 utf8.auto.check:4 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Users\april\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\april\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.14.2) from:C:\Program Files (x86)\AutoIt3 input:C:\Users\april\Documents\Logo\JRB\AutoIt\AutoBOT\AWD10\AWD10.au3 +>23:22:20 AU3Check ended.rc:0 >Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\april\Documents\Logo\JRB\AutoIt\AutoBOT\AWD10\AWD10.au3" --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop --> IE.au3 T3.0-2 Error from function _IELoadWait, $_IESTATUS_ClientDisconnected (-2147417848, Browser has been deleted prior to operation.) --> IE.au3 T3.0-2 Error from function _IEFormElementGetObjByName, $_IESTATUS_InvalidObjectType --> IE.au3 T3.0-2 Error from function _IEFormElementGetObjByName, $_IESTATUS_InvalidObjectType --> IE.au3 T3.0-2 Error from function _IELoadWait, $_IESTATUS_InvalidObjectType () --> IE.au3 T3.0-2 Error from function _IEAction(click), $_IESTATUS_InvalidDataType --> IE.au3 T3.0-2 Error from function _IEFormElementGetValue, $_IESTATUS_InvalidDataType +>23:22:23 AutoIt3.exe ended.rc:0 +>23:22:23 AutoIt3Wrapper Finished. >Exit code: 0 Time: 3.105 Here are the errors.
      --> IE.au3 T3.0-2 Error from function _IELoadWait, $_IESTATUS_ClientDisconnected (-2147417848, Browser has been deleted prior to operation.)
      --> IE.au3 T3.0-2 Error from function _IEFormElementGetObjByName, $_IESTATUS_InvalidObjectType
      --> IE.au3 T3.0-2 Error from function _IEFormElementGetObjByName, $_IESTATUS_InvalidObjectType
      --> IE.au3 T3.0-2 Error from function _IELoadWait, $_IESTATUS_InvalidObjectType ()
      --> IE.au3 T3.0-2 Error from function _IEAction(click), $_IESTATUS_InvalidDataType
      --> IE.au3 T3.0-2 Error from function _IEFormElementGetValue, $_IESTATUS_InvalidDataType
      And here is my HTML code.
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Language" content="en-us" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled 1</title> <style type="text/css"> .style1 { text-align: left; } .style3 { font-family: Arial; font-size: 9pt; color: #CC00FF; margin: 0; padding: 0; } .style4 { font-family: Arial; } .style5 { font-size: 9pt; } .style6 { color: #CC00FF; } .style7 { background-color: #FF9999; } .style8 { font-family: Arial; font-size: 7pt; color: #CC00FF; } .style9 { font-size: 7pt; } .style10 { border: 2px solid #CC00FF; } .style11 { text-align: center; } .style12 { border: 1px solid #CC00FF; } .style13{ clear: both; width: 525px; height: 45px; background: url(file:///C:/Users/april/Documents/JRB/AutoIt/AutoBOT/AWD10/lockedby.png) no-repeat; margin: 0; padding: 0; list-style: none; } .style14{ float: right; margin: 0px 0px 0 0; width: 290px; height: 25px; } .style15{ float: left; margin: 0px 0px 0 0; width: 290px; height: 25px; } .style16 { font-family: Arial; font-size: 2.5pt; color: #CC00FF; margin: 0; padding: 0; } .style17 { font-family: Arial; font-size: 7pt; color: #CC00FF; margin: 0; padding: 0; } .style18 { border-color: transparent; border: none; background-color:transparent; font-family: Arial; font-size: 8pt; } </style> </head> <body> <input type="button" name="getitem" value="get" onclick=" document.getElementById('filename').value = 'Life - ' + Random() + ' INVESTTAUTH - Process - Updateable - Assigned To: Jejeje - Create Date/Time: 2017-05-26-11.12.45.109044 - POL: 046054173 - TYPE: POLICY - SLA: 06/05/2017 ADMIN SYS: VP -PLC: 14' document.getElementById('businessarea').value = 'BusinessArea' + Random() document.getElementById('worktype').value = 'Worktype' + Random() "/><br/> <table style="width: 25%" align="center" class="style10"> <tr> <td style="width: 525px"> <img src="C:\Users\april\Documents\Logo\JRB\AutoIt\AutoBOT\AWD10\openitems.png" width="525px" height="28" /><br /> <div class="style13" style="height: 28px; width: 514px;"> <div class="style14" style="height: 11px; width: 110px;"> <label id="username"><span class="style16">&nbsp;</span><span class="style3"><br /> </span><span class="style17"> <script type="text/javascript"> var WinNetwork = new ActiveXObject("WScript.Network"); document.write(WinNetwork.UserName); </script> </span> </label> </div> <div class="style14" style="height: 11px; width: 52px;"> <label id="Label4"><span class="style16">&nbsp;</span><span class="style3"><br /> </span><span class="style17">Locked by </span> </label> </div> <div class="style15" style="height: 11px; width: 351px;"> <form method="post" id="openfile" class="style15" style="width: 341px"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input name="file" id="filename" class="style18" type="text" style="width: 200px; height: 10px" /></div> </form> </div> <label id="Label3"><span class="style3"><br/> &nbsp; </span><span class="style8"><strong>&nbsp;LTC Claims Indexing Form</strong></span><span class="style3"><br /> <br/> </span></label> <form method="post" id="formawddata" style="width: 495px"> <fieldset name="Group1" style="width: 495px" class="style12"> <legend class="style8"><strong>AWD Data</strong></legend> <table style="width: 100%"> <tr> <td style="width: 86px" class="style3">&nbsp;&nbsp;&nbsp;&nbsp; <span class="style9">Business Area:</span></td> <td style="width: 144px" class="style8"><input name="Text4" id="businessarea" class="style18" type="text" /></td> <td style="width: 45px" class="style8">Worktype:</td> <td class="style8"><input name="Text5" id="worktype" class="style18" type="text" /></td> </tr> </table> </fieldset><br /> </form> <form method="post" id="doc" style="width: 495px"> <fieldset name="Group1" style="width: 495px; height : 55px;" class="style12"> <legend class="style8"><strong>Document Data</strong></legend> &nbsp;&nbsp;&nbsp; <span class="style8">Document Type</span><br /> &nbsp;&nbsp;&nbsp; <span class="style4"><span class="style9"> <select name="Select1" id="documenttype" style="width: 363px"> <option></option> <option value="Doc1">Doc1</option> <option value="Doc2">Doc2</option> <option value="Doc3">Doc3</option> <option value="Doc4">Doc4</option> <option value="Doc5">Doc5</option> <option value="Doc6">Doc6</option> <option value="Doc7">Doc7</option> <option value="Doc8">Doc8</option> <option value="Doc9">Doc9</option> <option value="Doc10">Doc10</option> <option value="Doc11">Doc11</option> <option value="Doc12">Doc12</option> <option value="Doc13">Doc13</option> <option value="Doc14">Doc14</option> <option value="Doc15">Doc15</option> <option value="Doc16">Doc16</option> <option value="Doc17">Doc17</option> <option value="Doc18">Doc18</option> <option value="Doc19">Doc19</option> <option value="Doc20">Doc20</option> </select></span></span></fieldset><br /> </form> <form method="post" id="myForm"style="width: 495px; height: 103px;"> <fieldset name="Group1" style="width: 495px; height: 95px;" class="style12"> <legend class="style8"><strong>Policy Data</strong></legend> &nbsp;&nbsp;&nbsp; <span class="style8">Claim Number&nbsp;</span><span class="style3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="style8">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Policy Number/LTC ID</span><br /> &nbsp;&nbsp;&nbsp; <input name="Text1" id="claimnumber" type="text" style="width: 153px" class="style7" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input name="Text2" id="policynumber"type="text" style="width: 152px" class="style7" /><br /> &nbsp;&nbsp;&nbsp; <span class="style8">Company Code</span><br /> &nbsp;&nbsp;&nbsp; <span class="style7"> <span class="style4"><span class="style9"> <select name="Select2" id="companycode" style="width: 157px"> <option></option> <option value="CC00001">CC00001</option> <option value="CC00002">CC00002</option> <option value="CC00003">CC00003</option> <option value="CC00004">CC00004</option> <option value="CC00005">CC00005</option> <option value="CC00006">CC00006</option> <option value="CC00007">CC00007</option> <option value="CC00008">CC00008</option> <option value="CC00009">CC00009</option> <option value="CC000010">CC000011</option> <option value="CC000011">CC000011</option> <option value="CC000012">CC000012</option> <option value="CC000013">CC000013</option> <option value="CC000014">CC000014</option> <option value="CC000015">CC000015</option> <option value="CC000016">CC000016</option> <option value="CC000017">CC000017</option> <option value="CC000018">CC000018</option> <option value="CC000019">CC000019</option> <option value="CC000020">Doc20</option> </select></span></span></span></fieldset></form><table style="width: 95%; height: 114px;"> <tr> <td style="height: 23px; width: 212px;" class="style1"> <form method="post" style="width: 173px" > <fieldset name="Group1" style="width: 175px; height: 64px;" class="style12"> <legend class="style8"><strong>Routing</strong></legend> &nbsp;&nbsp;&nbsp; <span class="style4"><span class="style6"> <span class="style5"><span class="style9"> <input name="Radio1" type="radio" checked="checked" value="1" /></span></span><span class="style9">Indexed<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="style5"><span class="style9"> <input name="Radio1" type="radio" value="2" /> Reroute</span></span></span></span></fieldset></form></td> <td style="height: 23px"> <span class="style8">AWD Comments</span> <form method="post" id="awdcomments" style="width: 278px; height: 47px"> <textarea name="TextArea1" style="width: 273px; height: 59px" cols="20" class="style7"></textarea></form><br /> </td> </tr> </table> <br /> <div class="style11"> <input name="button1" type="button" onclick="myFunction()" value="Next Step"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; <input name="button2" type="button" onclick="myFunction()" value="Save" style="width: 91px"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input name="button3" type="button" onclick="myFunction()" value="Cancel" style="width: 94px"/> <script> function myFunction() { document.getElementById("doc").reset(); document.getElementById("myForm").reset(); document.getElementById("awdcomments").reset(); document.getElementById("formawddata").reset(); document.getElementById("openfile").reset(); document.getElementById("businessarea").reset(); document.getElementById("worktype").reset(); document.getElementById("documenttype").reset(); document.getElementById("policynumber").reset(); document.getElementById("companycode").reset(); document.getElementById("claimnumber").reset(); document.getElementById("Label4").reset(); } </script> <script type="text/javascript"> function Random() { return Math.floor(Math.random() * 10000000); } </script> <br /> <br /> </div> </td> </tr> </table> <p> &nbsp;</p> &nbsp; </body> </html> I hope you could assist me. Thank you in advance!
    • Ubermensch
      By Ubermensch
      Hello,
      I am currently trying to automatically click the "Yes" button in the ActiveX prompt/popup message after opening the IE (html).
      At 1st, I encounter the "Allow Blocked Content". I already resolve it just by changing settings in the IE Options. But after resolving the "Allow Blocked Content", there's a popup message appear.
      I have attached the ActiveX Prompt.
      Here is the 1st code that I try to use.
      #include <IE.au3> #include <MsgBoxConstants.au3> #include <WinAPI.au3> _IECreate("C:\Users\april\Documents\Logo\JRB\AutoIt\AutoBOT\AWD10\sampleAWD10.html",0,1,0) Local $oIE = _IEAttach("", "instance", 1) _IELoadWait($oIE) AdlibRegister("_ActiveXRun",250) Local $oLastName = _IEGetObjByName($oIE, "Text4") Local $oGetItem = _IEGetObjByName($oIE, "getitem") _IEAction($oGetItem, "click") MsgBox($MB_SYSTEMMODAL, "Form Element Value", _IEFormElementGetValue($oGetItem)) Func _ActiveXRun() $retWin = WinGetHandle("[Class:Button]","") $winTitle = "[HANDLE:" & $retWin &"]" $ctrlHandle = ControlGetHandle($winTitle,"", "[CLASS:Button; INSTANCE:2]") $ctrlTitle = "HANDLE:" & $ctrlHandle &"]" WinWaitActive($ctrlTitle,"[CLASS:Button; INSTANCE:2]",10) $k = ControlGetPos($winTitle, "","[CLASS:Button; INSTANCE:2]") $x = $k[0] $y = $k[1] WinActivate ($winTitle,"An ActiveX control on this page might be unsafe to interact with other parts of the page. Do you want to allow this interaction?") ControlFocus($winTitle,"An ActiveX control on this page might be unsafe to interact with other parts of the page. Do you want to allow this interaction?","[CLASS:Button; INSTANCE:2]") ControlClick($winTitle, "","[CLASS:Button; INSTANCE:2]","primary",1,$x,$y) ControlSend($winTitle, "", "[CLASS:Button; INSTANCE:2]", "{ENTER}", 0) EndFunc Here is the console output.
      >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\april\Documents\Logo\JRB\AutoIt\AutoBOT\AWD10\AWD10.1.au3" /UserParams +>12:44:11 Starting AutoIt3Wrapper v.17.224.935.0 SciTE v.3.7.3.0 Keyboard:00000409 OS:WIN_10/ CPU:X64 OS:X64 Environment(Language:0409) CodePage:0 utf8.auto.check:4 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Users\april\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\april\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.14.2) from:C:\Program Files (x86)\AutoIt3 input:C:\Users\april\Documents\Logo\JRB\AutoIt\AutoBOT\AWD10\AWD10.1.au3 +>12:44:11 AU3Check ended.rc:0 >Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\april\Documents\Logo\JRB\AutoIt\AutoBOT\AWD10\AWD10.1.au3" --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop "C:\Users\april\Documents\Logo\JRB\AutoIt\AutoBOT\AWD10\AWD10.1.au3" (31) : ==> Subscript used on non-accessible variable.: $x = $k[0] $x = $k^ ERROR ->12:44:24 AutoIt3.exe ended.rc:1 +>12:44:24 AutoIt3Wrapper Finished. >Exit code: 1 Time: 13.76 I also tried a simpler code.
      include <IE.au3> #include <MsgBoxConstants.au3> #include <WinAPI.au3> _IECreate("C:\Users\april\Documents\Logo\JRB\AutoIt\AutoBOT\AWD10\sampleAWD10.html",0,1,0) Local $oIE = _IEAttach("", "instance", 1) _IELoadWait($oIE) $k = ControlGetPos("[CLASS:#32770]", "","[CLASS:Button; INSTANCE:2]") $x = $k[0] $y = $k[1] ControlClick("[CLASS:#32770]", "","[CLASS:Button; INSTANCE:2]","primary",1,$x,$y) Local $oLastName = _IEGetObjByName($oIE, "Text4") Local $oGetItem = _IEGetObjByName($oIE, "getitem") _IEAction($oGetItem, "click") MsgBox($MB_SYSTEMMODAL, "Form Element Value", _IEFormElementGetValue($oGetItem)) There's no error in the console output for the 2nd code I have tried.
      And here is the Window Info for the ActiveX prompt.
      >>>> Window <<<< Title: Internet Explorer Class: #32770 Position: 580, 338 Size: 376, 146 Style: 0x94C808C4 ExStyle: 0x00010101 Handle: 0x00000000001516FA >>>> Control <<<< Class: Button Instance: 2 ClassnameNN: Button2 Name: Advanced (Class): [CLASS:Button; INSTANCE:2] ID: 1 Text: &Yes Position: 184, 77 Size: 80, 22 ControlClick Coords: 37, 12 Style: 0x50010000 ExStyle: 0x00000004 Handle: 0x00000000001215DE >>>> Mouse <<<< Position: 228, 120 Cursor ID: 0 Color: 0xFFFFFF >>>> StatusBar <<<< >>>> ToolsBar <<<< >>>> Visible Text <<<< &No An ActiveX control on this page might be unsafe to interact with other parts of the page. Do you want to allow this interaction? &Yes >>>> Hidden Text <<<<  

    • ChipConnJohn
      By ChipConnJohn
      Hello all,
      Here's a cleaned up version of my code:
      #include <IE.au3>
      #include <MsgBoxConstants.au3>
      #include <Array.au3>
      #include <String.au3>
      ;#include <ErrorHandler.au3>
      ; Open Greatsite.com
      Global $oIE = _IECreate ("http://www.greatsite.com")
      ; I'm logged in and on the forum page.  Now to navigate categories with unknown names.
      ; Grab all links on page, then only dive into the ones with the text "forum_id="
      ; as in ?bview=forum&forum_id=108343
      Global $oLinksCategoryPage = _IELinkGetCollection($oIE)
      Local $iNumLinks = @extended
              ;Now at the thread level. Navigate into each thread and look at timestamp
              Global $oLinksOfThreads = _IELinkGetCollection($oIE)
              For $oLinkThread In $oLinksOfThreads
                  If StringInStr($oLinkThread.href,"thread_id") Then
                      _IENavigate($oIE, $oLinkThread.href)
                      ;Need to find instance of Posted and read text after the href.
                      Local $sBodyText = _IEBodyReadText($oIE)
                      ;Find first instance of the word "Posted" and check the two words to the right of it.
                      Local $aArrayOfBodyText = _StringExplode($sBodyText," ",0)
                      ;_ArrayDisplay($aArrayOfBodyText, "The body text in Array form")
                      ;Local $iIndexOfPosted = _ArraySearch($aArrayOfBodyText,"days")
                      For $iIndex = 0 to ubound($aArrayOfBodyText) - 1
                          If StringInStr(StringLower($aArrayOfBodyText[$iIndex]), "posted") Then
                              ;The word Posted has been found. Look for "Just A moment ago", "minutes", and "minute"
                              Select
                                  Case StringLower($aArrayOfBodyText[$iIndex +1]) = "just"
                                      ;"Just a moment ago.  Grab this one.
                                  Case Stringlower($aArrayOfBodyText[$iIndex +2]) = "minute"
                                      ;"1 minute". Grab this one
                                  Case Stringlower($aArrayOfBodyText[$iIndex +2]) = "minutes"
                                      ;"x minutes. Grab this one
                              EndSelect
                              ;ExitLoop ;Found the first one.  I'm done.
                          EndIf
                      ;Need to back out to Threads in Category
                      Next
                      _IEAction($oIE,"back")
                  EndIf
              Next
              ;Back out to Category List
              _IEAction($oIE,"back")
          EndIf
      Next
      _IEQuit($oIE)
       
      The script works fine until I hit the Next to go back to the For $oLinkThread In $oLinksOfThreads.  Any line that I put after that crashes with an error.  It's like the For loop is going one too many iterations and there is no object in the variable.
      The requested action with this object has failed.:
      If StringInStr($oLinkThread.href,"thread_id") Then
      If StringInStr($oLinkThread^ ERROR
      Thanks,
      -John
       
    • Lights_On
      By Lights_On
      Hi All,
      Below is an example of my code that will reproduce an issue I am having, all be it an issue that sometimes occurs and sometimes does not.
      #include <WinAPI.au3> #include <IE.au3> #include <MsgBoxConstants.au3> #include <Array.au3> Call ("Project") Func Project() Local $WaitTime = 10000 ; Set the time between checks in miliseconds While 1 $hwnd = WinGetHandle("[active]") If Not @error Then ; Ensure 'WinGetHandle' worked. Local $WinClassName = _WinAPI_GetClassName($hwnd) If $WinClassName = "IEFrame" Then ; If the curent window is an IE exploere instance then... Local $Object = _IEAttach($hwnd, "embedded") If not @error Then Local $url = _IEPropertyGet($Object, 'locationurl') If not @error Then Local $Split = StringSplit($url, "/") If $Split[0] > 2 Then ; This stops an error if the array did not have enought rows e.g no url to display form row 3. If Not $Split[3] = "" Then ; Dont bother if no url e.g blank msgbox(0, "URL is:", $Split) EndIf EndIf EndIf EndIf EndIf EndIf Sleep($WaitTime) WEnd EndFunc The issue is from IE.au3 and the error message is attached.  I am able to reproduce it is I run the scrip, load an instance of IE, then navigate to a different page such as google or something.
       
      I have looked in the code for IE.au3 and it reference to a function “__IEControlGetObjFromHWND(ByRef $hWin)” however I am not using this function so am a little unsure why or how this error is being called or what I can do to stop it?
       
      Any advice / help would be gratefully appreciated.
      Thank you.

    • taylansan
      By taylansan
      Hi All, 
      I'm using an online translator for Spanish in which you give the verb and website gives the conjugations. The website I'm using is: http://www.spanishdict.com/conjugate/tener where "tener" means "to have" in English. 
      In the screenshot, you can see the present tense (5 yellow highlighted items) and the imperfects (5 blue boxes). I don't need to get the translation for "vosotros", so I didn't make any color on that row. I'm trying to get these 10 translations to be written on the output for my code. But my code is so simple (because I couldn't go into the div / tr / td): 
      #include <IE.au3> #include <Array.au3> Local $sSpanishWord = "tener" ;to have ;Local $sSpanishWord = "abrir" ;to open Local $oIE = _IECreate ("http://www.spanishdict.com/conjugate/" & $sSpanishWord) ;http://www.spanishdict.com/conjugate/tener ;http://www.spanishdict.com/conjugate/abrir ;== Try using _IETagNameAllGetCollection Local $oElements = _IETagNameAllGetCollection($oIE) For $oElement In $oElements If $oElement.id Then ConsoleWrite("Tagname: " & $oElement.tagname & @CRLF & "id: " & $oElement.id & @CRLF & "innerText: " & $oElement.innerText & @CRLF & @CRLF) EndIf Next ;== Try using _IETagNameGetCollection Local $sTable Local $oTableCells Local $oTableRows = _IETagNameGetCollection($oIE, "tr") For $oTableRow In $oTableRows $sTable = "" $oTableCells = _IETagNameGetCollection($oTableRow, "td") ;I don't know how to continue from here on Next I used the IE to find out the tr / td stuff, but I think I'm lost. 
      P.S: The verb "tener" can be difficult, because it has red letters because of irregular. The verb "abrir" can be much easier, because it's a regular verb.