Jump to content
FrancescoDiMuro

Urgent: make _IE* automation faster

Recommended Posts

FrancescoDiMuro

Good morning everyone :)

I worked a bit on a little project of mine, and I managed to do what I was trying to do, or, automate a quiz in AutoIt.

Now, everything works fine but, in order to achieve what I'm trying to achive, I'd like to make this script run faster.

I'll attach a portion of the code in order to let you understand what my script does.

$objIE_h1 = _IETagNameGetCollection($objIE, "h1") ; Take the text of the answer
        If @error Then
            ConsoleWrite("Errore durante la lettura degli h1 nella pagina. - Errore: " & @error & @CRLF)
        Else
            For $objElement In $objIE_h1
                $strInnerText = $objElement.innerText
            Next

            Select
                Case StringInStr($strInnerText, "QUESTION") ; Here is the question
                    ; PS4 PRO

                    $objSpans = _IETagNameGetCollection($objIE, "span") ; Answers are stored here
                    For $objElement In $objSpans
                        If $i >= 4 Then
                            $strAnswer = $objElement.innerText ; Take the text of the answer n° 0, 1, 2, 3
                            If StringInStr($strAnswer, "CORRECT ANSWER") Then ; If I match the correct answer, then, I have to click on the input with answer id = answer_i
                                $j = $i - 4
                                $objInput = _IEGetObjById($objIE, "answer_" & $j)
                                If @error Then
                                    ConsoleWrite("Errore durante la lettura della risposta #" & $i & " - Errore: " & @error & @CRLF)
                                Else
                                    _IEAction($objInput, "click")
                                    If @error Then
                                        ConsoleWrite("Errore durante il click sull'elemento. - Errore: " & @error)
                                    Else
                                        ConsoleWrite($j & ") Risposta: " & $strAnswer & @CRLF)
                                        ExitLoop
                                    EndIf
                                EndIf
                            EndIf
                            $i+=1
                        Else
                            $i+=1
                        EndIf
                    Next
                    $i = 0
                    $j = 0

This is what my script does.

Questions are 20, in which I have 15 multiple choice question, 2 images ( on which I use _IEImgClick() ), and 3 text inputs ( a simple send with the text I have to enter ).

How can I make all of these, faster?

If I reach this goal, I've probably done one of my best goals in life, and I'd like to share my happiness with you, giving a huge donation to this fantastic community!

Thanks for your help :)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

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:

In case I am violating some pseudo Forum rule, or I am doing something wrong, I want let you know that I'm not doing this on purpose, and for this, I kindly ask you to send me a private message about the "bad content" I posted, in order to edit/remove it, and to not be warned wrongly.
Thanks in advance.

 

Share this post


Link to post
Share on other sites
JLogan3o13

@FrancescoDiMuro you have been around long enough to know you're not going to get a lot of help by posting a non-runnable snippet of code and then giving us a blanket "help me make this faster". If you would like help on improving the entire code, you have to post the entire code ;)


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
FrancescoDiMuro

@JLogan3o13

Hi Master :)

Yes, you are right.

I'm sorry if I can't post the entire code, because it's a project which I'd like to not share at the moment.

I could ask now: "Is there a way to make a script faster, about _IE* automation?"

Thanks in advance :)


Click here to see my signature:

Spoiler

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:

In case I am violating some pseudo Forum rule, or I am doing something wrong, I want let you know that I'm not doing this on purpose, and for this, I kindly ask you to send me a private message about the "bad content" I posted, in order to edit/remove it, and to not be warned wrongly.
Thanks in advance.

 

Share this post


Link to post
Share on other sites
JLogan3o13

Yes


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
FrancescoDiMuro

Do I have to open another thread or, can you modify the title, please? :)

Thanks :)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

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:

In case I am violating some pseudo Forum rule, or I am doing something wrong, I want let you know that I'm not doing this on purpose, and for this, I kindly ask you to send me a private message about the "bad content" I posted, in order to edit/remove it, and to not be warned wrongly.
Thanks in advance.

 

Share this post


Link to post
Share on other sites
JLogan3o13

You can modify your own title by editing the initial post.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
FrancescoDiMuro

@JLogan3o13

Didn't know about that! 

Thanks again :)

Have a good day :)


Click here to see my signature:

Spoiler

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:

In case I am violating some pseudo Forum rule, or I am doing something wrong, I want let you know that I'm not doing this on purpose, and for this, I kindly ask you to send me a private message about the "bad content" I posted, in order to edit/remove it, and to not be warned wrongly.
Thanks in advance.

 

Share this post


Link to post
Share on other sites
FrancescoDiMuro

Bump :)


Click here to see my signature:

Spoiler

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:

In case I am violating some pseudo Forum rule, or I am doing something wrong, I want let you know that I'm not doing this on purpose, and for this, I kindly ask you to send me a private message about the "bad content" I posted, in order to edit/remove it, and to not be warned wrongly.
Thanks in advance.

 

Share this post


Link to post
Share on other sites
Danp2

There are definitely ways to improve your script, but I can't say that it will be any faster. For example.

$objIE_h1 = _IETagNameGetCollection($objIE, "h1") ; Take the text of the answer
        If @error Then
            ConsoleWrite("Errore durante la lettura degli h1 nella pagina. - Errore: " & @error & @CRLF)
        Else
            For $objElement In $objIE_h1
                $strInnerText = $objElement.innerText
            Next

could be rewritten as follows, assuming there is only a single H1 element

$objIE_h1 = _IETagNameGetCollection($objIE, "h1", 0) ; Take the text of the answer
If @error Then
   ConsoleWrite("Errore durante la lettura degli h1 nella pagina. - Errore: " & @error & @CRLF)
Else
   $strInnerText = $objIE_h1.innerText
EndIf

 

Share this post


Link to post
Share on other sites
FrancescoDiMuro

Thanks @Danp2:)

Other suggestions? :)

There is a bug when the script is too fast... It selects the correct answer, but seems that the system doesn't recognize it and then, I have a bad answer ( even if it's right ).

Thanks again :)


Click here to see my signature:

Spoiler

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:

In case I am violating some pseudo Forum rule, or I am doing something wrong, I want let you know that I'm not doing this on purpose, and for this, I kindly ask you to send me a private message about the "bad content" I posted, in order to edit/remove it, and to not be warned wrongly.
Thanks in advance.

 

Share this post


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

Other suggestions?

1. Remove "Urgent" from your topic B)

2. Stop making us work so hard to help you. Provide all information in one place.

  • Like 1

Share this post


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

1. Remove "Urgent" from your topic B)

I need to make this script faster for today, so, it's urgent.

1 minute ago, Danp2 said:

2. Stop making us work so hard to help you. Provide all information in one place.

I tested the script many times, and lately I had this little bug.

Don't answer if you don't want to.

And, by the way, your solution

1 hour ago, Danp2 said:

$objIE_h1 = _IETagNameGetCollection($objIE, "h1", 0) ; Take the text of the answer If @error Then    ConsoleWrite("Errore durante la lettura degli h1 nella pagina. - Errore: " & @error & @CRLF) Else    $strInnerText = $objIE_h1.innerText EndIf

doesn't work.


Click here to see my signature:

Spoiler

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:

In case I am violating some pseudo Forum rule, or I am doing something wrong, I want let you know that I'm not doing this on purpose, and for this, I kindly ask you to send me a private message about the "bad content" I posted, in order to edit/remove it, and to not be warned wrongly.
Thanks in advance.

 

Share this post


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

I need to make this script faster for today, so, it's urgent.

cw-urgent.jpeg

16 minutes ago, FrancescoDiMuro said:

I tested the script many times, and lately I had this little bug.

Don't answer if you don't want to.

Fine... I won't.

20 minutes ago, FrancescoDiMuro said:

And, by the way, your solution doesn't work.

As I stated, it should work if there is only one H1 element. Again, you've failed to provide the necessary details. How did it fail?

Share this post


Link to post
Share on other sites
FrancescoDiMuro

 

Just now, Danp2 said:

cw-urgent.jpeg

Really kid? :)

1 minute ago, Danp2 said:

Fine... I won't.

You've already did it.

 

1 minute ago, Danp2 said:

As I stated, it should work if there is only one H1 element. Again, you've failed to provide the necessary details. How did it fail?

I really don't know... Even if I have onlyone <h1> element in my page, it fails...

Search "h1" (2 hits in 1 file)
  C:\Users\maybe\Downloads\IE_Automation.html (2 hits)
    Line 70:         <h1><span class="questionid">1. </span>QUESTION</h1>
    Line 70:         <h1><span class="questionid">1. </span>QUESTION</h1>

One is the open tag <h1>, and the second one is the close tag </h1>.

KTHXBYE :)


Click here to see my signature:

Spoiler

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:

In case I am violating some pseudo Forum rule, or I am doing something wrong, I want let you know that I'm not doing this on purpose, and for this, I kindly ask you to send me a private message about the "bad content" I posted, in order to edit/remove it, and to not be warned wrongly.
Thanks in advance.

 

Share this post


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

Was an error generated? Was the element not found?

The function _IETagNameGetCollection doesn't match any h1, either in 0 nor in 1 index.


Click here to see my signature:

Spoiler

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:

In case I am violating some pseudo Forum rule, or I am doing something wrong, I want let you know that I'm not doing this on purpose, and for this, I kindly ask you to send me a private message about the "bad content" I posted, in order to edit/remove it, and to not be warned wrongly.
Thanks in advance.

 

Share this post


Link to post
Share on other sites
Danp2

That doesn't make any sense. If the original command returned a collection containing 1 object, then the command I posted should work. An index of 1 would mean there were multiple H1s, so it does make sense that this failed.

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

    • milkmoron
      By milkmoron
      https://www.autoitscript.com/forum/topic/153520-iuiautomation-ms-framework-automate-chrome-ff-ie/?do=findComment&comment=1156373 At least we have an element title: [Entered By:] class: [WindowsForms10.EDIT.app.0.30495d1_r9_ad1] Having the following values for all properties: Title is: <Entered By:> Class := <WindowsForms10.EDIT.app.0.30495d1_r9_ad1> controltype:= <UIA_EditControlTypeId> ,<50004> , (0000C354) 322;370;736;184 *** Parent Information top down *** 3: Title is: <View Activity> Class := <WindowsForms10.Window.8.app.0.30495d1_r9_ad1> controltype:= <UIA_WindowControlTypeId> ,<50032> , (0000C370) 306;72;784;605 "Title:=View Activity;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1"" 2: Title is: <> Class := <WindowsForms10.Window.8.app.0.30495d1_r9_ad1> controltype:= <UIA_PaneControlTypeId> ,<50033> , (0000C371) 314;103;768;542 "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1"" 1: Title is: <> Class := <WindowsForms10.Window.8.app.0.30495d1_r9_ad1> controltype:= <UIA_PaneControlTypeId> ,<50033> , (0000C371) 314;103;749;451 "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1"" 0: Title is: <Delete> Class := <WindowsForms10.Window.8.app.0.30495d1_r9_ad1> controltype:= <UIA_PaneControlTypeId> ,<50033> , (0000C371) 314;122;749;432 "Title:=Delete;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1"" ;~ *** Standard code maintainable *** #include "UIAWrappers.au3" AutoItSetOption("MustDeclareVars", 1) _UIA_setVar("oP1","Title:=View Activity;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1") ;View Activity _UIA_setVar("oP2","Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1") ; _UIA_setVar("oP3","Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1") ; _UIA_setVar("oP4","Title:=Delete;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1") ;Delete _UIA_setVar("EnteredBy:.mainwindow","title:=Entered By:;classname:=WindowsForms10.EDIT.app.0.30495d1_r9_ad1") ;~ Actions split away from logical/technical definition above can come from configfiles ;~_UIA_Action("oP1","highlight") _UIA_Action("oP1","setfocus") ;~_UIA_Action("oP2","highlight") _UIA_Action("oP2","setfocus") ;~_UIA_Action("oP3","highlight") _UIA_Action("oP3","setfocus") ;~_UIA_Action("oP4","highlight") _UIA_Action("oP4","setfocus") _UIA_action("EnteredBy:.mainwindow","setfocus") ;~ *** Standard code Flexible*** #include "UIAWrappers.au3" AutoItSetOption("MustDeclareVars", 1) Local $oP3=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=View Activity;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1", $treescope_children) _UIA_Action($oP3,"setfocus") Local $oP2=_UIA_getObjectByFindAll($oP3, "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1", $treescope_children) _UIA_Action($oP2,"setfocus") Local $oP1=_UIA_getObjectByFindAll($oP2, "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1", $treescope_children) _UIA_Action($oP1,"setfocus") Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=Delete;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1", $treescope_children) _UIA_Action($oP0,"setfocus") _UIA_setVar("EnteredBy:.mainwindow","title:=Entered By:;classname:=WindowsForms10.EDIT.app.0.30495d1_r9_ad1") _UIA_action("EnteredBy:.mainwindow","setfocus") Need some help selecting this defining it as a variable to save and then insert the text within, to the same application but different account.
    • 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. 
    • FMS
      By 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  
    • TheSaint
      By TheSaint
      TeraCopy Timer - A program of mine, front end really, that I have been working on (on & off) for some time, but not shared here before, that I recall. Third party program TeraCopy is required.
      Many of you will be familiar with TeraCopy, and it has been discussed here at AF on several occasions, in various sub forums, including Chat.
      BE ADVISED - I still use an older version of TeraCopy (v2.27), a goody but an oldy, so have only tested my program with that. It may work with the newer v3.xx, or may be easily adjusted to do so, but I have not yet gone that route. Likewise, I only use it with Win 7 and Win XP, but I don't imagine there should be any issues with newer Windows. Add to that, my program being devised and created in AutoIt v3.3.0.0.
      So what is TeraCopy Timer and why might you need it?
      --------------------------------------------------------------------------------------
      Those familiar with TeraCopy use, know you can run multiple copy or move jobs either simultaneously or concurrently (one immediately after another has finished). With the free version at least, you have no control over precise order or timing, and no way to deal (without manual interaction) with the pesky Thumbs.db files in Win XP. TeraCopy Timer allows you to do all those things, and in a batch fashion.
      --------------------------------------------------------------------------------------
      Some screenshots and brief explanation
      Main Window
      Minimalist Window
      This new WAIT feature is the simplest and best way to use the program generally (in my view) ... but check out the following, as it is not always the case.
      Advanced Delay Window
      WARNING - It should go without saying, that you take all the usual precautions. For instance, don't use move with the only copy you have of precious files. BACKUP BACKUP BACKUP! Don't hold me liable for anything, except for being a nice guy who likes to share.
      TeraCopy Timer v2.8.zip  (see detail at Post #34)
      TeraCopy Timer v2.9.zip  (see detail at Post #35)
      Enjoy!
      OLDER DOWNLOADS
      P.S. I am not affiliated in any way with those who created and provide the excellent third party program - TeraCopy.
    • BogdanNicolescu
      By BogdanNicolescu
      While 1 / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / WEnd OR:

       
      HotKeySet("{ESC}", "Terminate") While 1 MouseClick("Right",674,422) MouseClick("Left",673,447) Sleep(2000) / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / MouseClick("Left",675,339) SLeep(3000) WEnd Func Terminate()     Exit 0 EndFunc  
      Sorry if i should't let this here to be found by newbies like me -.-'
×