FrancescoDiMuro

Urgent: make _IE* automation faster

17 posts in this topic

#1 ·  Posted (edited)

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.

Share this post


Link to post
Share on other sites



@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

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

Share this post


Link to post
Share on other sites

Yes


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

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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.

Share this post


Link to post
Share on other sites

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

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

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.

Share this post


Link to post
Share on other sites
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.

1 person likes this

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

 

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.

Share this post


Link to post
Share on other sites

You've stated that it fails, but haven't told us how you determined this. Did the script not run? Was an error generated? Was the element not found?

What happened?!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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

    • 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?
      I devised my program for two main reasons really, based on giving me greater control, using the Free version of TeraCopy, which has some limitations (perhaps even with the paid full version). My program utilizes the features of the TeraCopy command-line.
      1. I was fed up with Thumbs.db files regularly halting the process in Win XP or preventing a folder being deleted after a move. Only happens with Win XP.
      2. I wanted to automate delays between jobs, allowing all HDD's to rest periodically when doing large and lengthy jobs. Letting HDD's heat up too much, can have tragic results or considerably shorten their lifespan. Prevention is better than cure or just relying on monitoring software etc.
      --------------------------------------------------------------------------------------
      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

      You can browse to set the Source and Destination paths, or like me, just use Drag & Drop to those inputs.
      Once the Destination path has been set, the MIN (minimalist GUI) button becomes available. In Minimal mode, you get a further level of automation, once initial options are set, and thus less prompts ... none in fact, as jobs are created automatically based on either COPY or MOVE.
      Minimalist Window

      In the Minimalist mode, you can only use Drag & Drop to add a source file or folder, and COPY or MOVE is permanently set when the window first opens, via a choice prompt.
      Assigning a WAIT is simple and easy, and is the latest feature added to the program ... I used a much more complex variant before that (see Advanced Delay).

      The program now displays three file size reports.
      Individual Size of the current (last added) job (Blue label).
      Total Size of all jobs combined (Black label).
      Subtotal Size for each grouping of jobs, defined by a WAIT selection (Red label).
      You toggle between Black and Red, by just clicking that label. If no WAIT has been set, then the values will be the same.
      The wait of 5 minutes in the screenshot above is set for the source shown. It means wait 5 minutes before copying (or moving) that source.
      More sources added from that point, add to a new subtotal. To see the previous subtotal, you need to be at the main (MAX) window, and select the prior job.
      So every time a WAIT is clicked for a source a new subtotal count is started.

      In the screenshot above, you can see the Job name, and that it is Job number 5 order wise. MOVE has been set for that job.
      Selecting Job 4, you will see the previous (complete) Subtotal. Selecting job 3 (in this instance), you would see the subtotal up to that job.
      Click the red Total label and it will change to Black, and show you the total size over all, as shown in the second screenshot above.
      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

      The Advanced Delay Options, are a further level of automation, added during the early stages of development, before I thought to create the Minimalist window and show Sizes. It was before I decided to put a lot more effort into the program. As with all my programs though, it is continual use that eventually dictates what I ultimately want to happen, to make my life easier ... simpler, better, smarter, quicker.
      The main difference between this older method, and the new WAIT one, where you specify delays precisely, is that the program attempts to determine the best moments to pause, based on various factors, which you setup and can vary between different types of Job sessions.
      The chief purpose for all the advanced options, is an attempt to cater for the difference between moving a small number of big files and a lot of small files. Moving or Copying lots of small files (hundreds or thousands), as many would know, can heat up a HDD far quicker and to a much higher temperature than a small number of (even very) large files. I guess that is primarily due to the sheer number of indexes that need to be created, and with small files are done at a staggering rate.
      Which method you use, is up to you, and should be governed by the type of job. Both methods can be used together, but not advised if you don't want the possibility of unnecessary extra long delays. EDIT - That said, you could use the WAIT option just for a delayed start of the first job ... perhaps your PC is busy doing something else until then, but you want to go and do something else for a bit, and have it all done by the time you return (i.e. watch a movie).
      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.0.zip
      Enjoy!
      P.S. I am not affiliated in any way with those who created and provide the excellent third party program - TeraCopy.
    • nassausky
      By nassausky
      Hi all,
       
      Anyone have any idea how to close all open tabs except a specific one I manually open.  Assuming I don't know what is open in all the tabs except just the one I want to keep open.
       
      I didn't want to use sendkeys and I was trying to use the following code to list the title (or url) of the 3 open tabs and  after I got that part working I would just close the other 2. This sample only displays the title of the first open tab
      #include <IE.au3> Const $ie_new_in_tab = 0x0800 $oIE = _IECreate("https://www.autoitscript.com") __IENavigate($oIE, "https://www.autoitscript.com/forum/", 1, $ie_new_in_tab) ;(obj,url,wait,param) __IENavigate($oIE, "https://www.google.com/", 1, $ie_new_in_tab) ;(obj,url,wait,param) Local $aIE[1] $aIE[0] = 0 Local $i = 1, $oIE While 1     $oIE = _IEAttach("", "instance", $i)     If @error = $_IEStatus_NoMatch Then ExitLoop     ConsoleWrite(_IEPropertyGet($oIE, "title") & @CRLF)     ReDim $aIE[$i + 1]     $aIE[$i] = $oIE ;each item holds object     $aIE[0] = $i ;first item holds count     $i += 1 WEnd MsgBox($MB_SYSTEMMODAL, "Browsers Found", "Number of browser instances in the array: " & $aIE[0]) ; This doesn't return the list of tabs in the console just the first tab  
      Thanks for any and all help
    • toto22
      By toto22
      I'm trying to click on Java Dropbox using IE. However, I'm running into problems. There is a Dropbox "Please Select" with two options "Buy" and "Sell".
      I'm able to click on a drop box (please see code below) but i'm unable to select "Buy" or "Sell"".
      Local $sMyString = "Please Select" ;############ ENTER ############# Local $oLinks = _IELinkGetCollection($oIE) For $oLink In $oLinks Local $sLinkText = _IEPropertyGet($oLink, "innerText") If StringInStr($sLinkText, $sMyString) Then _IEAction($oLink, "click") ExitLoop EndIf Next  
      Please help
       
         
    • Gowrisankar
      By Gowrisankar
      Hello everyone,
      I'm working on a task where, a PDF file is opened (in IE browser) when I click a link in a website.
      I have to read the first page of the PDF to find particular strings. Can you please share some ideas?
    • Seminko
      By Seminko
      Hey,
      i would like to set a value into an INPUT field.
      Checked the _IEFormElementSetValue function but that does require _IEFormGetObjByName and this is where the problem comes in. The input field I want to write to is not a part of a form tag. It is part of a table.
      <input type="text" class="w2" id="nabidka_vozidel_formular_tach_od" name="nabidka_vozidel_formular_tach_od" onchange="GLOBAL.pocetInzerceNZ(&quot;nabidka_vozidel_formular&quot;,&quot;tach_od&quot;,&quot;&quot;);" autocomplete="off"> I tried this but that didn't work:
      $oDownloadSamples = _IEGetObjById($oIE, "nabidka_vozidel_formular_tach_od") _IEFormElementSetValue($oDownloadSamples, "123") If you want to try the site I'm working with is https://www.tipcars.cz/. There is a menu on the top left hand side and if you click the "vyhledat" button the input fields will show up.
      Thanks