Sign in to follow this  
Followers 0
Damien35

Automate my internet trips

6 posts in this topic

Hello,

so I would like to automate some of my daily tasks on internet :)

I looked well in the autoit documentation et succeed in some little programs, which I am proud of :) (so I understand a little programmation even if it's not my training)

So what I want is recover some text from an internet page and copy/paste it into word.

And I have some problems:

1- after a first identification that I do like this:

$o_form = _IEFormGetObjByName ($oIE, 0)
$o_login = _IEFormElementGetObjByName ($o_form, "login" )
$o_password = _IEFormElementGetObjByName ($o_form, "password" )
$o_signin = _IEFormElementGetObjByName ($o_form, "Submit")
$username = "toto"
$password = "tata"
_IEFormElementSetValue ($o_login, $username)
_IEFormElementSetValue ($o_password, $password)
$oSelect = _IEFormElementGetObjByName ($o_form, 0)
_IEFormElementOptionselect ($oSelect, "a list", 1, "byText")
_IEAction ($o_signin, "click")

On the following page, I can't redo that:

$WhatInterestme = _IEFormElementGetObjByName ($o_form, "WhatInterestme")
_IEFormElementSetValue ($WhatInterestme, "1")

to insert some text...

2- How can I click on an icon "+" without use the MouseClick?

html code from the place I would like to clic:

<input type="submit" value="+" onclick="document.getElementById('toto').value

3- How select a text area, which is in a table (I mean make the equivalent as I do with CTRL+selection with mouse), then copy/paste this selection in word?

_IEAction ($_selection, "copy")

#include <Word.au3>
$oWordApp = _WordCreate (@ScriptDir & "\Test.doc")
$oDoc = _WordDocGetCollection ($oWordApp, 0)        
$oDoc.Range.insertAfter ("Text from internet page")

Thanks a lot for your help :D

if informations are missing don't hesitate to ask :)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

EDIT : for the third question : I began to find an answer:

$oTable = _IETableGetCollection ($oIE, 6)
$aTableData = _IETableWriteToArray ($oTable, True)
_ArrayDisplay($aTableData)

this display exactly what I want! but i can't copy it into word...

$oDoc.Range.insertAfter ($aTableData)

this just write : " [object] " in word

it makes an error when I want to do

$oDoc.Range.insertAfter ($oTable)

how can I split the table and write it separatly in word? (or notepad)

Edited by Damien35

Share this post


Link to post
Share on other sites

For 1) Please insure taht you run your code in SciTe and pay attention to the messages written to the console. the $oFrom value becomes invalid after a nerw page load

For 2) use _IEFormElementGetCollection with an index to get the input button, then use _IEAction with Click

For 3) you need to read about arrays in the helpfile. $aTableData is an array that you need to get a siggle element from to write to word

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Thanks for your answer

1) you were right, I thought about it too

$oIE2 = _IECreate("")
$o_form2 = _IEFormGetObjByName ($oIE2, "WhatInterestme")

the form variable changed while the new page loaded, however I'm not sure that my method is "clean" (create a new window, no need to re-login)...

=> problem solved

2) again thanks

_IEFormElementGetCollection($o_form2, 5)
_IEAction ($ovariable, "click")

I did not understood that I had to "count" to know at what "time" I had to clic => 5e collection in my case

=> problem solved

3) here too I made progresses

But I still can't separate the content of the "array" window to send it to word

#include <Array.au3>
#include <Word.au3>
#include <IE.au3>
$oIE2 = _IECreate("")
$oTable = _IETableGetCollection ($oIE2, 6)
$aTableData = _IETableWriteToArray ($oTable, True)
_ArrayDisplay($aTableData)

$oWordApp = _WordCreate (@ScriptDir & "\Test.doc")            
$oDoc = _WordDocGetCollection ($oWordApp, 0)
$iRetCode = _ArrayToClip( $aTableData, 1 )
$oDoc.Range.insertAfter (ClipGet())

I still have an error because it's not the good dimension... (which is [10][10 for example)

I'm blocked... a little help?

Share this post


Link to post
Share on other sites

I think you need to study arrays in the helpfile a bit more. _IETableWriteToArray returns a 2-D array and it's selements are addressed like this:

$sValue = $aTableData[0][0]

I do not believe that _ArrayToClip works on anything but 1-D arrays, so that is not a good approach.

Please, when you state that you get an error - post that error. Don't make us guess what it is.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Update of my problem:

I succeed (finally!) (Thanks to DaleHohm!) to solve my problems :)

for word, for those who cares: :

WinActivate("Test.doc - Microsoft Word")    
    $oTable = _IETableGetCollection ($oIE2, 6)
    $aTableData = _IETableWriteToArray ($oTable, True)
    For $j = 0 To 9
        $sValue = $aTableData[$j][1]            
        $oWordApp = _WordCreate (@ScriptDir & "\Test.doc")            
        $oDoc = _WordDocGetCollection ($oWordApp, 0)
        $oDoc.Range.insertAfter ($j+1)
        $oDoc.Range.insertAfter (@TAB)    
        $oDoc.Range.insertAfter ($sValue)  
        $oDoc.Range.insertAfter (@LF)      
        Sleep(1000)
    Next

however I have a new problem:

I would like to clic several times at the same place (same button)

I tried severals methods:

1-

$ocliclic =  _IEFormElementGetCollection($o_form2, 5)
    _IEAction ($ocliclic, "click")
    Sleep(1000)
    $ocliclic =  _IEFormElementGetCollection($o_form2, 5)
    _IEAction ($ocliclic, "click")

this click only once on what interests me!

2- when I remove the Sleep function => he clicks instantaneously 2 times!

3- when I put in commentaries the second time I declare $ocliclic i receive this error message:

Posted Image

4- when I do:

$ocliclic =  _IEFormElementGetCollection($o_form2, 5)
    _IEAction ($ocliclic, "click")
    Sleep(1000)
    $ocliclic2 =  _IEFormElementGetCollection($o_form2, 5)
    _IEAction ($ocliclic2, "click")

he does not click on $cliclic2

changement of methods :

5-

$ocliclic =  _IEFormElementGetCollection($o_form2, 5)
    _IEAction ($ocliclic, "focus")
    Send("{ENTER}")
    Sleep(1500)
    Send("{ENTER}")

so idem : when I put sleep function, he makes only one clic, if I don't put it he makes 2 in one shot...

That's the last step of my macro and then i'm fisnished!!!

Thanks for your help

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
Sign in to follow this  
Followers 0