Jump to content

Recommended Posts

Posted

Hi,

I just started to do scripting using AutoIT. I wanted to create simple script which automate opening a web site.

The script is able to run IE and stop. It did not continue to open the web site.

Below is the script:

Run ("C:\Program Files\Internet Explorer\iexplore.exe")

WinWaitActive ( "Internet Explorer")

ControlSend("Internet Explorer", "", "Edit1", "www.cnn.com")

Send ( "{ENTER}" )

Anyone can help me to advise what is wrong with the script?

Thanks,

Jetta

Posted (edited)

Hi there. Hows it going.

First off welcome to the forums.

I'd suggest you have a poke around the helpfile and look at the _IE Functions.

Although if you just want to open it, then ShellExecute should work- also has the advantage of opening in the defaul browser.

ShellExecute ("http://www.google.com.au")

If you wanted it in IE though, try this:

ShellExecute ("iexplore", "http://www.google.com.au")

Cheers,

Brett

Edited by BrettF
Posted

$URL    = "www.cnn.com"
             $fd        = FileOpen(@TEMPDir & "url.url",2)
             if $fd = -1 Then Exit
             FileWriteLine($fd,"[InternetShortcut]")
             FileWriteLine($fd,"URL=" & $URL)
             FileClose($fd)
             Run(@comspec & " /c " & chr(34) & @TEMPDir & "url.url" & chr(34))

Just put that code into Scite and Run it. simple as that :)

System task ---> My first GUICalculator v1.0 ---> My version of the calculatorNetZilla 1.0 --> Web browserEmail Sender --> You can Send emails with this without opening a web browser
Posted

Many thanks for providing the solution.

But, sorry for my stupidity, just curious why I can't code using just the following functions : run, winwait and send/controlsend?

thanks.

Posted (edited)

from .chm help-file

<quote>

Window Titles and Text (Advanced)

...

Mode 1 (default)

Matches partial titles from the start

...

Mode 2

Matches any substring in the title.

</quote>

when i start ie using run(...) command - it has "about:blank - Microsoft Internet Explorer" window info (idea is it starting title from the name of the opened page)

I think u need the second mode of searching window title.

It can be set using AutoItSetOption ( "option" [, param] )

sorry if wrong, newbie

upd. and u need to clear the edit1 string :) have any ideas how 2 do it?

autoitsetoption("WinTitleMatchMode",2)

Edited by Arnautov
Posted

autoitsetoption("WinTitleMatchMode",2)

run ("d:\Program Files\Internet Explorer\iexplore.exe")

winwaitactive("Internet Explorer")

ControlSend("Internet Explorer", "", "Edit1", "www.cnn.com")

Send ( "{F6}")

Send ( "{BS}" )

Send ( "www.cnn.com" )

Send ( "{ENTER}" )

i don't like this code. It worked. But i hate it. Shure other ways exists.

Posted

Arnautov,

thanks for providing a solution.

but should the following line

ControlSend("Internet Explorer", "", "Edit1", "www.cnn.com")

be ommited as it will be done by the following codes:

Send ( "{F6}")

Send ( "{BS}" )

Send ( "www.cnn.com" )

Send ( "{ENTER}" )

Strangely, in few tries, the script will just open my default home page instead of cnn.com.

any ideas why?

Posted

yes, BrettF, u'r solution works fine. Thnx.

Question is changed, as i understand it :)

2Jetta

yes :) that's a normal problem of a modern software o:) User act's faster than a software reacts ;)

U can recreate the problem without using autoit, just start iexplore and type F6 when u c IE window. Depending on the power of u'r computer u can miss the selecting of address string :mad:

sleep(n) command can help

and, yes, the controlsend string can b omitted, i think.

actually, it would be more adequate to select edit1 field without using send("{f6}") command. RTFM whispered something like ControlFocus ( "title", "text", controlID ), i tried it without any positive results.

Posted

ok, ignoring the "easiest ever made" solution by BrettF i found how 2 fill the address string in IE:

autoitsetoption("WinTitleMatchMode",2)

run ("d:\Program Files\Internet Explorer\iexplore.exe")

winwaitactive ("Internet Explorer")

sleep(700)

controlclick ("Internet Explorer", "", "[CLASS:Edit;INSTANCE:1]")

send ( "{BS}" )

send ( "www.cnn.com" )

send ( "{ENTER}" )

and must say it won't work without sleep! 700 - empiric value, 675 doesn't work :) Think it differ according to the computers productivity/

Posted

BrettF,

your solution works fine. FYI, I just want to create a script just as the way we do it manually (execute IE, put the url address and press enter).

Arnautov,

thanks again for your advise.

Posted

I see. I was getting the impression you prefered the hard way :)

But if its possible an easier to do it the way I have shown why don't you pick that path? Is there a reason for you needing it manually?

Cheers,

Brett

Posted

well, my idea was to check availability of doing it. This can be used in other tasks, so all i done was just a simple reseach.

also it shows some restrictions and flavours of autoit.

the best way to study something is to use it? Exept destructive techs, ye...

Posted

I tried your script it didnt work as you stated. I have ammended it slightly without rewriting to get it working

Opt("WinDetectHiddenText", 1)

Opt("WinTitleMatchMode", 2)

Opt("SendCapslockMode", 0)

Opt("TrayIconDebug", 0)

Opt("WinWaitDelay", 1000)

Opt("SendKeyDelay", 100)

Run ("C:\Program Files\Internet Explorer\iexplore.exe")

WinWait( "Internet Explorer")

WinActive ( "Internet Explorer")

WinWaitActive ( "Internet Explorer")

ControlSetText("Internet Explorer", "", "Edit1", "")

Sleep(2000)

ControlSend("Internet Explorer", "", "Edit1", "www.cnn.com")

Send ( "{ENTER}" )

Posted

OMG! IT'S ALIVE! :)

works beatiful before sending enter. Sending enter doesn't work for me.

I think the cause is missed focus.

just inserted

controlclick ("Internet Explorer", "", "[CLASS:Edit;INSTANCE:1]")
before sending enter and script works fine. I wonder if we have so differ reacting of IE.

anyway, thnx for demonstration :) Had fun and made a note o:)

Posted

How does this go?

$link = "http://www.google.com.au"
$PID = Run("C:\Program Files\Internet Explorer\iexplore.exe")
$hWnd = _GetHwndFromPID($PID)
Sleep (1000)
WinWait($hWnd)
ToolTip("Win Wait done")
WinActive($hWnd)
ToolTip("Win Active done")
WinWaitActive($hWnd)
ToolTip("Win Activated done")
ControlSend($hWnd, "", "", "{ESC}")
Sleep (200)
ToolTip("Sent ESC")
ControlSetText($hWnd, "", "[CLASS:Edit; INSTANCE:1]", $link)
Sleep (200)
ToolTip("Set Text")
ControlSend($hWnd, "", "[CLASS:Edit; INSTANCE:1]", "{ENTER}")
ToolTip("Send Enter")

Func _GetHwndFromPID($PID)
    $hWnd = 0
    $stPID = DllStructCreate("int")
    Do
        $winlist2 = WinList()
        For $i = 1 To $winlist2[0][0]
            If $winlist2[$i][0] <> "" Then
                DllCall("user32.dll", "int", "GetWindowThreadProcessId", "hwnd", $winlist2[$i][1], "ptr", DllStructGetPtr($stPID))
                If DllStructGetData($stPID, 1) = $PID Then
                    $hWnd = $winlist2[$i][1]
                    ExitLoop
                EndIf
            EndIf
        Next
        Sleep(100)
    Until $hWnd <> 0
    Return $hWnd
EndFunc  ;==>_GetHwndFromPID

Cheers,

Brett

Posted

loop can be never exited.

And in my case the tip "Win Activated done" can't be reached! The tooltip "Win Active done" is the last one i see.

Going to dig it later.

Posted

hehe, i get at the humor :)

that's the legacy of my installation mistake. IE's path is correct in my case. And my hands need to be replanted to the right position.

Posted

Glad it works, but it sure is an awful lot of code when you could just do this:

#include <IE.au3>

$oIE = _IECreate("www.cnn.com")

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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...