Jump to content
FMS

IE - reading <div style=?>

Recommended Posts

FMS

Hello,

I'm trying to read a div element and wait until it hits 100%.
The structure is like :
<div class="progress-bar" style="width: 48.0219%;  overflow: hidden; "></div>

And want to wait until :
<div class="progress-bar" style="width: 100%;  overflow: hidden; "></div>

because afther this there will be an redirection whish i don't know the URL from and want to catsh this URL.
And want to push a button on this redidertion page.

Is there a best pratice way how to do this or is there a better way to wait for the redirection?
Maybe wait until button exist or something?

Does anybody could give me some tips about this challange?

 

thnx in advanced.

 

#include <IE.au3>

Global $IE_flvto = _IECreate("https://www.website.com/",0,1,1,1)
Global $oForm = _IEFormGetObjByName ($IE_flvto, "convertForm")
Global $oText = _IEFormElementGetObjByName ($oForm, "convertUrl")
_IEFormElementSetValue ($oText, "some text")
_IEFormSubmit($oForm)

;wait for redirection

;if redirection loaded push button

 


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites
FrancescoDiMuro

Good morning @FMS:)
Have you already took a look about _IELoadWait() function? 

Best Regards,


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
FMS

@FrancescoDiMuro , Yes i did.
unfortunaly loadwait doesn't wait for the div to be 100% and the redirection occured :(


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites
FrancescoDiMuro

@FMS
What object are you passing at the function _IELoadWait()? :)


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
FMS

@FrancescoDiMuro _IELoadWait($IE_flvto)


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites
FrancescoDiMuro

@FMS
From the Help file:

Quote

Parameters

$oObject : Object variable of an InternetExplorer.Application or DOM element

Why don't you try to pass the div object instead of the web page? :)


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
FMS

@FrancescoDiMuro, I din't know we could do that. thanks for the pointer.

I must say I don't know how to do that.
Could you explain a little bit futher :)


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites
FMS
Posted (edited)

I'm a little stuck and maybe I'm thinking it totaly wrong.
could you look at this code ? :

#include <IE.au3>

Global $IE_flvto = _IECreate("https://www.website.com/",0,1,1,1)
Global $oForm = _IEFormGetObjByName ($IE_flvto, "convertForm")
Global $oText = _IEFormElementGetObjByName ($oForm, "convertUrl")
_IEFormElementSetValue ($oText, "sometext")
_IEFormSubmit($oForm)
Global $oDivp = _IEPropertyGet($IE_flvto, "progress-bar")
;~ Global $oDiv = _IEFormElementGetObjByName ($IE_flvto, "progress-bar")
Global $odiv = _IEPropertyGet ( $oDivp , "width" )

_IELoadWait($odiv)
ConsoleWrite("waited")


 

Edited by FMS

as finishing touch god created the dutch

Share this post


Link to post
Share on other sites
Juvigy

That wont work. Can you post the source-code of the page or the page itself ? You need to get an reference to the DIV element before you pass it to the IELOADWAIT function. You cant do it by _IEGetObjById or _IEGetObjByName or _IETagNameGetCollection. Check out the help files and examples.

You can also try passing the form object to the ieloadwait - not sure if it is going to work though.

Global $oForm = _IEFormGetObjByName ($IE_flvto, "convertForm")

Share this post


Link to post
Share on other sites
FMS
#include <IE.au3>

Global $IE_flvto = _IECreate("https://www.flvto.biz/",0,1,1,1)
Global $oForm = _IEFormGetObjByName ($IE_flvto, "convertForm")
Global $oText = _IEFormElementGetObjByName ($oForm, "convertUrl")
_IEFormElementSetValue ($oText, "https://www.youtube.com/watch?v=2H0yWKdZM8g")
_IEFormSubmit($oForm)

Global $oDivs = _IEGetObjByName($IE_flvto,"progress-bar")

;~ Global $oDivp = _IEPropertyGet($IE_flvto, "progress-bar")
;~ Global $oDiv = _IEFormElementGetObjByName ($IE_flvto, "progress-bar")
;~ Global $odiv = _IEPropertyGet ( $oDivp , "width" )
_IELoadWait($oForm)
ConsoleWrite("waited" & @CRLF )

 

Untitled.png


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites
Danp2

FWIW, I believe _IELoadWait ends up looking at the document's readystate no matter what you pass in as the first parameter.

Share this post


Link to post
Share on other sites
FrancescoDiMuro

@Danp2
So the documentation has to be corrected :)
Always if it is what you are saying :)


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
Danp2
1 minute ago, FrancescoDiMuro said:

@Danp2
So the documentation has to be corrected :)
Always if it is what you are saying :)

No... id on't think so, unless I misunderstand what you're saying. The docs state the following --

Quote

When document objects or DOM elements are passed to _IELoadWait(), it will check the readyState of the container elements up to and including the parentWindow.

I think that some folks have a misconception that passing an element to _IELoadWait will result in the code waiting for that element to "finish loading", which isn't the case. If you examine the code, you will see that it identifies the type of object being passed in and uses that information to determine how to obtain it's containing document.

Share this post


Link to post
Share on other sites
FrancescoDiMuro
3 minutes ago, Danp2 said:

I think that some folks have a misconception that passing an element to _IELoadWait will result in the code waiting for that element to "finish loading"

Without reading the Help file carefully, it is what you just described :D
 


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
FMS

@Danp2, @FrancescoDiMuro :wtf:I realy want to join this conversation and ask a smart question.......
but I realy don't understand what you are saying :D

 

So you are saying it isn't posible?
Or there is another way?


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites
FrancescoDiMuro

@FMS
You are welcome :D
We are saying that, in the Help file, the _IELoadWait() functions seems that could be used for wait for a DOM Object too, but that's not what it is used for, since, if you look closer in the IE Library, you can see that the DOM Object is used for "arrive" at it's document, so, the load is always referred to the page, and not to the DOM Object :)


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
Danp2

Completely untested, but maybe you could do something like this --

Func _IERedirectWait(ByRef $oObject, $iDelay = 0, $iTimeout = -1)

    If Not IsObj($oObject) Then
        __IEConsoleWriteError("Error", "_IENavigate", "$_IESTATUS_InvalidDataType")
        Return SetError($_IESTATUS_InvalidDataType, 1, 0)
    EndIf

    If Not __IEIsObjType($oObject, "documentContainer") Then
        __IEConsoleWriteError("Error", "_IENavigate", "$_IESTATUS_InvalidObjectType")
        Return SetError($_IESTATUS_InvalidObjectType, 1, 0)
    EndIf

    Local $sCurrentURL = _IEPropertyGet($oObject, "locationurl")
    Local $hIERedirectWait = TimerInit()
    Local $iError = $_IESTATUS_Success, $bAbort

    If $iTimeout = -1 Then $iTimeout = $__g_iIELoadWaitTimeout

    While Not (_IEPropertyGet($oObject, "locationurl") <> $sCurrentURL Or $bAbort)
        If (TimerDiff($hIERedirectWait) > $iTimeout) Then
            $iError = $_IESTATUS_LoadWaitTimeout
            $bAbort = True
        EndIf
        Sleep(100)
    WEnd

    Switch $iError
        Case $_IESTATUS_Success
            Return SetError($_IESTATUS_Success, 0, 1)
        Case $_IESTATUS_LoadWaitTimeout
            __IEConsoleWriteError("Warning", "_IERedirectWait", "$_IESTATUS_LoadWaitTimeout")
            Return SetError($_IESTATUS_LoadWaitTimeout, 3, 0)
    EndSwitch
EndFunc

 

Share this post


Link to post
Share on other sites
FMS

@Danp2 Nice this totaly works.
onostly I'm nut shure how :huh2:
Could you explaine a bit of your code ?
This so i understand and learn a bit more of (auto)it :)


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites
Juvigy
Posted (edited)

@Danp2, smart workaround.

@FMS, What the code does is basically wait until the location URL changes. This is the main script idea:

While Not (_IEPropertyGet($oObject, "locationurl") <> $sCurrentURL Or $bAbort)

I was going to go for getting the DIV element and reading its properties to see when it finishes, but this way is faster and more simple.

Edited by Juvigy
NA

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

    • rm4453
      By rm4453
      Hello,
       
      I am currently writing a program that parses a massive table from a website, and need a way to add a progress bar while parsing.
      I am currently using the function _IETableWriteToArray($oObj, True) to parse the array. I need the progress bar to update as the table is parsed, not just at the end of the parsing.
      Any help at all would be very much appreciated!
       
      *EDIT --> The array I am left with after parsing is $array[0-50000][16]
    • SkysLastChance
      By SkysLastChance
      I have a goofy problem. I am hoping someone could shed some light. The example is not going around the text box. It is way off. 
      I have seen some post blaming IE 11, however I have IE11 on my desktop and it works fine.
      Is there anything I can do that might fix this? 
       
      ; Open a browser with the form example and get a reference to the form ; textarea element. Get the coordinates and dimensions of the text area, ; outline its shape with the mouse and come to rest in the center #include <IE.au3> Local $oIE = _IE_Example("form") Local $oForm = _IEFormGetObjByName($oIE, "ExampleForm") Local $oTextArea = _IEFormElementGetObjByName($oForm, "textareaExample") ; Get coordinates and dimensions of the textarea Local $iScreenX = _IEPropertyGet($oTextArea, "screenx") Local $iScreenY = _IEPropertyGet($oTextArea, "screeny") Local $iWidth = _IEPropertyGet($oTextArea, "width") Local $iHeight = _IEPropertyGet($oTextArea, "height") ; Outline the textarea with the mouse, come to rest in the center Local $iMousespeed = 50 MouseMove($iScreenX, $iScreenY, $iMousespeed) MouseMove($iScreenX + $iWidth, $iScreenY, $iMousespeed) MouseMove($iScreenX + $iWidth, $iScreenY + $iHeight, $iMousespeed) MouseMove($iScreenX, $iScreenY + $iHeight, $iMousespeed) MouseMove($iScreenX, $iScreenY, $iMousespeed) MouseMove($iScreenX + $iWidth / 2, $iScreenY + $iHeight / 2, $iMousespeed)  
       
    • SkysLastChance
      By SkysLastChance
      So I have two things I am trying to click.
      Policy which works.
      $oInputs3 = _IETagNameGetCollection($oIE, "div") For $oInput3 in $oInputs3 If StringStripWS($oInput3.innertext,1) = "Policy" Then $target = $oInput3 _IELoadWait($target,"",70000) ExitLoop EndIf Next _IEAction($target, "click")  

      And Add Insurance which I havent been able to get to work. 
      $oInputs2 = _IETagNameGetCollection($oIE, "div") For $oInput2 in $oInputs2 If StringStripWS($oInput2.innertext,1) = "Add Insurance" Then $target = $oInput2 _IELoadWait($target,"",70000) ExitLoop EndIf Next _IEAction($target, "click")

      Any Ideas on what I am doing wrong?  I feel like it might be the spaces between >  Add Insurance  < but I am not sure. 
    • Juvigy
      By Juvigy
       Hi Guys,
      Could you please try out my script on win10 machine (simple site scrape)? One of my users complains it doesnt work on his win10, but it works fine on my win7. The error he gets is on the .FireEvent call. I think it is admin rights or IE / Edge issue, but don't have win10 to test it out.
      Thanks in advance.
       
      #include <IE.au3> #include <Array.au3> #include <Excel.au3> Global $oIE,$string Dim $destination[8] = ["Viña del Mar", "Rancagua", "Pucon", "Copiapo", "Temuco", "La serena", "Puerto Montt", "Valdivia"] Dim $FinalResult[1][3] $FinalResult[0][0] = "Destination" $FinalResult[0][1] = "Ida" $FinalResult[0][2] = "Vuelta" Attach("https://www.turbus.cl/") If IsObj($oIE) = 0 Then ConsoleWrite("IE error??"&@CRLF) $oIE = _IECreate() EndIf For $i=0 to UBound($destination)-1 Step 1 _IENavigate($oIE,"https://www.turbus.cl/") $site1 = _IEGetObjById($oIE,"j_id_id122:cmbCiudadOrigenV2") While @error Sleep(1000) $site1 = _IEGetObjById($oIE,"j_id_id122:cmbCiudadOrigenV2") WEnd $site2 = _IEGetObjById($oIE,"j_id_id122:cmbCiudadDestinoV2") $date1 = _IEGetObjById($oIE,"j_id_id122:calIdaV2InputDate") $date2 = _IEGetObjById($oIE,"j_id_id122:calVueltaV2InputDate") $buttun1 = _IEGetObjById($oIE,"j_id_id122:botonContinuarV2") $site1.Value = "Santiago" $site2.Value = $destination[$i] $date1.Value = @MDAY+1&"/"&@MON&"/"&@YEAR $date2.Value = @MDAY+4&"/"&@MON&"/"&@YEAR _IEAction($buttun1,"click") _IELoadWait($oIE) $array = GetResult(GetData()) If IsArray($array) = 0 OR UBound($array,1) < 1 Or UBound($array,2) < 2 Then MsgBox(0,UBound($array,1), UBound($array,2)) _ArrayDisplay($array,"$array") ContinueLoop EndIf _ArrayAdd($FinalResult,"Santiago-"&$destination[$i]&"|"&$array[0][0]&"|"&$array[0][1]) Next ;~ _ArrayDisplay($FinalResult) Local $oExcel = _Excel_Open() If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $oWorkbook = _Excel_BookNew($oExcel) If @error Then MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example", "Error creating the new workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Close($oExcel) Exit EndIf _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $FinalResult, "A1") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example 2", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Func GetData() Local $string1,$string2 $ida = _IEGetObjById($oIE,"tbIda_lbl") While @error Sleep(1000) $ida = _IEGetObjById($oIE,"tbIda_lbl") WEnd _IEAction($ida,"click") Sleep(2000) $result1 = _IEGetObjById($oIE,"pnlReglaIda:idPersonalizaPasaje:tb") While @error $ida.FireEvent("onmouseover") Sleep(1000) $ida.FireEvent("onclick") Sleep(1000) $result1 = _IEGetObjById($oIE,"pnlReglaIda:idPersonalizaPasaje:tb") WEnd $string1 = $string1 & $result1.innertext&@CRLF $vuelta = _IEGetObjById($oIE,"tbVuelta_lbl") _IEAction($vuelta,"click") Sleep(2000) $result2 = _IEGetObjById($oIE,"pnlReglaVuelta:idPersonalizaPasajeRegreso:tb") While @error $vuelta.FireEvent("onmouseover") Sleep(1000) $vuelta.FireEvent("onclick") Sleep(1000) $result2 = _IEGetObjById($oIE,"pnlReglaVuelta:idPersonalizaPasajeRegreso:tb") WEnd $string2 = $string2 & $result2.innertext&@CRLF Return $string1&"|"&$string2 EndFunc Func Attach($atachadres) Local $i = 1 While 1 $oIE = _IEAttach("", "instance", $i) If @error = $_IEStatus_NoMatch Then $oIE = 0 ExitLoop EndIf If StringLeft(_IEPropertyGet($oIE, "locationurl"),StringLen($atachadres)) = $atachadres Then ExitLoop $i += 1 WEnd EndFunc Func GetResult($String) Dim $Master[0][2] ,$Master2[1][2] $2strings = StringSplit($String,"|",2) $Strings = StringSplit($2strings[0],@CRLF,2) $Strings = _ArrayUnique($Strings) For $i=0 to UBound($Strings)-1 Step 1 $Data = StringSplit($Strings[$i],"$",2) $add = _ArrayToString($Data) _ArrayAdd($Master,$add) Next For $i=UBound($Master,1)-1 to 0 Step -1 If $Master[$i][1] = "" Then _ArrayDelete($Master,$i) Next _ArraySort($Master,0, 0, 0,1) $Master2[0][0] = $Master[0][0]&$Master[0][1] Dim $Master[0][2] $Strings = StringSplit($2strings[1],@CRLF,2) $Strings = _ArrayUnique($Strings) For $i=0 to UBound($Strings)-1 Step 1 $Data = StringSplit($Strings[$i],"$",2) $add = _ArrayToString($Data) _ArrayAdd($Master,$add) Next For $i=UBound($Master,1)-1 to 0 Step -1 If $Master[$i][1] = "" Then _ArrayDelete($Master,$i) Next _ArraySort($Master,0, 0, 0,1) $Master2[0][1] = $Master[0][0]&$Master[0][1] Return $Master2 EndFunc  
    • FMS
      By FMS
      Hello,
      I try to get all the text from a news site around a subject.
      The first run I get all the text inside a attribute in an array.
      When i try to go back and reload another page it chrashes and think it because "$oIE.GoBack"
      I couldn't find anything in the help/forum around this subject.
      Do I need to reload the $oIE or something afther an X.GoBack?
      The error i got is :
      if $oTag2.GetAttribute("class") == "NewsDetail" Then if $oTag2^ ERROR I'm not shure why I got this error, maybe someone could explain?
      Also I'm open for some pointers in this test script because I'm pretty new in working whit the IE.UDF
      Maybe there is an simpler way to get the same results?

      test script:
      #include <IE.au3> #include <MsgBoxConstants.au3> #include <Array.au3> HotKeySet("{ESC}", "Terminate") Global $oIE = _IECreate("https://www.iex.nl/Zoeken/Nieuws.aspx?q=air%20france") ;get first subject Global $oLink1 = _IEGetObjById($oIE, "ctl00_ctl00_Content_LeftContent_NewsSearch_repNews_ctl00_linkNews") Sleep(500) _IEAction($oLink1, "click") Sleep(500) Global $oTags = _IETagNameGetCollection($oIE, "div") Global $aResults[1] For $oTag In $oTags if $oTag.GetAttribute("class") == "NewsDetail" Then _ArrayAdd($aResults, $oTag.innerTEXT) EndIf Next $aResults[0] = UBound($aResults) - 1 _ArrayDisplay($aResults, "Episodelist") ConsoleWrite($aResults[1] & @CRLF) $oIE.GoBack ;get second subject Global $oLink2 = _IEGetObjById($oIE, "ctl00_ctl00_Content_LeftContent_NewsSearch_repNews_ctl01_linkNews") Sleep(500) _IEAction($oLink2, "click") Sleep(500) Local $oTags2 = _IETagNameGetCollection($oIE, "div") Local $aResults2[1] For $oTag2 In $oTags2 if $oTag2.GetAttribute("class") == "NewsDetail" Then _ArrayAdd($aResults2, $oTag2.innerTEXT) EndIf Next $aResults2[0] = UBound($aResults2) - 1 ConsoleWrite($aResults2[1] & @CRLF) Func Terminate() _IEQuit($oIE) Exit EndFunc ;==>Terminate  
×