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

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
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!

How to get your question answered on this forum!

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

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
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

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
FrancescoDiMuro

@JLogan3o13

Didn't know about that! 

Thanks again :)

Have a good day :)


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
FrancescoDiMuro

Bump :)


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

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

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
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

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
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

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
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

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

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

    • Seminko
      By Seminko
      Wrote a script that grabs all of the IP addresses from Netflix's IP log, checks the IPs and returns suspicious activity.
      Everything works as it should but only when _IECreate is set to visible. When visible is set to false, it fails to login for some reason.
      Any ideas what might cause it and/or how to circumvent that?
    • nooneclose
      By nooneclose
      I need to send a string of text to this popup and click on the ok button to save it.
      Here is the code I have so far:
      ;Start IE Sleep(7000) $oIE = _IECreate("http://www.google.com") Sleep(500) _IELoadWait($oIE) $hIE = _IEPropertyGet($oIE, "hwnd") ; Get Handle of the IE window Sleep(500) WinSetState($hIE, "", @SW_MAXIMIZE) ;Wait for a browser page load to complete Sleep(3000) _IENavigate($oIE, "https://properURL.com") Sleep(8000) _IELoadWait($oIE) ;Attach to a browser control embedded in another window $oIE = _IEAttach("https://"properURL.com", url") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $oIE = ' & $oIE & @CRLF & '>Error code: ' & @error & ' Extended code: 0x' & Hex(@extended) & @CRLF) ;### Debug Console Sleep(2000) ;Get the title of the webpage ;Local $wTitle = _IEPropertyGet($oIE, "title") ;MsgBox($MB_SYSTEMMODAL, "Webpage title:", $wTitle) ;Clicks the new button Sleep(3000) _IEAction($nWorkOrderB, "focus") _IEAction($nWorkOrderB, "click") Sleep(5000) ;Store the Element names where the important data will be sent ;Store the long description button Local $wLongDButton = _IEGetObjById($oIE, "m65d795a4-img") ;Store the long Description field id Local $wComments = _IEGetObjById($oIE, "ma6499a9c-rte_iframe") ;Store the ok button id that is in the long description Local $wCommOk = _IEGetObjById($oIE, "m74031266-pb") ;******************************************************************************* ; Send the stored data to the proper field ;******************************************************************************* ;Click the long description button Sleep(300) _IEAction($wLongDButton, "focus") _IEAction($wLongDButton, "click") Sleep(300) ;Sends the Comments Sleep(500) _IEAction($wComments, "focus") _IEAction($wComments, "click") Sleep(500) _IEFormElementSetValue($wComments, "hello darkness my old friend") ;Click the ok button Sleep(500) _IEAction($wCommOk, "focus") _IEAction($wCommOk, "click") Sleep(500)  
      Here is the popup:

    • hemichallenger
      By hemichallenger
      Hello,
      If anyone can help, it would be greatly appreciated. The code is just an example and similar to the issue with an internal webpage. I'm trying to autofill than click the submit button. I get the same error running the script.
      _IEFormElementSetValue, $_IESTATUS_InvalidObjectType
      IEGetObjById, $_IESTATUS_NoMatch
      Is it possible to edit the <textarea></textarea>  field with AutoIt?  If anyone could assist me on how. Than I could have a better understanding and chance in figuring it out on my main script. Thank you
      #include <IE.au3> Local $oIE1 = _IECreate ("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_textarea") _IELoadWait($oIE1) local $oFormCollection = _IEFormGetCollection($oIE1,0) local $oid = _IEGetObjByid($oFormCollection, "iframeResult") _IEFormElementSetValue($oid, "test") sleep (2000) Local $oIE2 = _IECreate ("https://www.w3schools.com/html/tryit.asp?filename=tryhtml_scripts_intro") _IELoadWait($oIE2) $oForm2 = _IEFormGetCollection($oIE2,0) $oClickMe = _IEGetObjById($oForm2, "demo") _IEAction($oClickMe, "focus") _IEAction($oClickMe, "click")
    • Blueman
      By Blueman
      Hey Guys,
      Hope that you can help me with something, maybe this is a bug in the new version of AUTOIT but first i will check it with you to know for sure.
      I have made a simple GUI with a Embedded IE Object, then i would like to read the HTML with _IEBodyReadHTML(), easy right?
      When i use the old IE.au3 include from a year back or so, it is working fine!
      When i use the new IE.au3 include came with the new installation that is currently available on autoitscript.com it isnt working (i get a result that says; 0).
      Let me show you.
       
      Working Example
      #include <GUIConstantsEx.au3> #include <IE_EmbeddedVersioning.au3> #include <IE_PreVersion.au3> ;Older Version Example() Func Example() ; Create a GUI with various controls. Local $hGUI = GUICreate("Example", 1000, 1000) Local $idOK = GUICtrlCreateButton("OK", 310, 370, 85, 25) Global $oIE_1 = _IECreateEmbedded() ; CREATE IE OBJECT(S) GUICtrlCreateObj($oIE_1, 355, 5, 600, 360) _IENavigate($oIE_1, "https://www.google.nl", 1) Local $CheckHTML_T = _IEBodyReadHTML($oIE_1) ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) MsgBox(48,"",$CheckHTML_T) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idOK ExitLoop EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>Example  
      Failing Example
      #include <GUIConstantsEx.au3> #include <IE_EmbeddedVersioning.au3> #include <IE.au3> ;New Version Example() Func Example() ; Create a GUI with various controls. Local $hGUI = GUICreate("Example", 1000, 1000) Local $idOK = GUICtrlCreateButton("OK", 310, 370, 85, 25) Global $oIE_1 = _IECreateEmbedded() ; CREATE IE OBJECT(S) GUICtrlCreateObj($oIE_1, 355, 5, 600, 360) _IENavigate($oIE_1, "https://www.google.nl", 1) Local $CheckHTML_T = _IEBodyReadHTML($oIE_1) ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) MsgBox(48,"",$CheckHTML_T) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idOK ExitLoop EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>Example  
      I have attachted all files and i am testing on Windows 10 with the latest SciTe Program (Not compiled). 
      When i compile the script it is showing the same result.
      Thanks guys!
      IE_PreVersion.au3
      IE.au3
      IE_EmbeddedVersioning.au3
    • ademon
      By ademon
      Hi. I can open the editor with out problems but I can not compile because it is placed on another partition diferent from C.
      Can you provide an update of this bug?


×