herewasplato

Navigating IE without COM

6 posts in this topic

#1 ·  Posted (edited)

I have thought about posting this info for several months now... even created and killed the post twice. Using COM [_IE UDF] to get around within IE is so much better (or so I'm told) that I just hesitated suggesting anything less. However, COM continues to be a bit much for some beginners and there is a body of users (like myself) that just have not had the need to use it YET.

The script is heavily commented and is not posted as an attachment for the sake of those really new to the forum that might be hesitant to download code that they have not seen. (Believe me, some users fear the act of downloading.)

The script shows one simple way to get to some links and "text boxes".

It "goes to" Yahoo's mail site

It does not wait for all of the page to "load" or be rendered (be drawn on the screen)

It "tabs around" to find the link to Yahoo's secure logon page and then tabs back up to the username and password fields

As with most scripts, if the web page changes a lot, the script will have to be changed to accommodate; however, this "tab around" method does not care how many advertisements there are on the site or how many other links come and go. It only cares that the link of interest retains its name and its relationship to the fields of interest.

I welcome all comments, especially if any of the info offered is just plain wrong...but I'll mention this up front: I know that there are better ways to do things like start IE, but I wanted to keep the script as simple and understandable as possible... so I probably will not be changing that line.

For the really really new user:

copy the text in the block below

paste it into notepad

save it as yahoo-test.au3

(take note of where you save it)

double click on the file just saved

Edit1: Yahoo changed the link that I was using as a reference.

Edit2: Corrected yet another typo.

Edit3: Yahoo changed the link that I was using as a reference.

Edit4: Yahoo changed the link that I was using as a reference.

; For use with AutoIt 3.1.1 or higher.
; Blame herewasplato for this long post and script.

; This is a sample script to show one way to locate a link
; or a field within a web page using MS Internet Explorer.
; For FireFox users: surf with FireFox, script with IE/COM.

; There are better ways to accomplish this, but this one simple
; method and works for most web pages that I have encountered.
; Some links you cannot get to by sending "TAB" to IE but there
; may be a way to get to those links too - just not via this script.


; This tells AutoIt how to match window titles.
AutoItSetOption("WinTitleMatchMode", 2)
; See the help file for details of other matching modes.

; This line just complicates my explanation of what is going on.
AutoItSetOption("WinDetectHiddenText", 1)
; Wait until the end of the script for more info on this.

; This tells AutoIt how long to pause
; after a successful window-related operation.
AutoItSetOption("WinWaitDelay", 1); (milliseconds)
; See the help file for more details.

; This helps during the debug of the script
AutoItSetOption("TrayIconDebug", 1);0-off

; Get the mouse out of the way.
MouseMove(0, 0, 10)
; If the mouse happens to be where a link could appear in the
; web page, then it could mess up this script.

; Starts IE (for most people) and goes to yahoo's mail site for this example.
Run("C:\Program Files\Internet Explorer\IEXPLORE.EXE [url="http://mail.yahoo.com%22%29"]http://mail.yahoo.com")[/url]

; wait for a window with "Sign in to Yahoo" in the title
WinWait("Yahoo", "")
; active that window - just in case
WinActivate("Yahoo", "")
; wait until that window is active
WinWaitActive("Yahoo", "")

; In most cases, there is no need to wait for the entire web
; page to load before locating the link you want.

Do; This loop repeats the code between the Do and Until lines.
    Send("{TAB}")
    Sleep(50); <<Slows the loop down, change the speed here.
Until WinExists("Yahoo", "forgot_pw")
; See the notes at the end of the script.

; TO LOCATE A FIELD INSTEAD OF A LINK:
; Tab to the link closest to the field you want and then tab
; forward or backwards as needed.
Send("+{TAB 4}AutoIt.....{TAB}.....")
; The "+" in front of a "{TAB}" tells AutoIt to act like you
; 1. held down the Shift key,
; 2. pressed the Tab Key
; 3. and then released the Shift key.
; It makes the "IE cursor" tab backwards through the links and
; fields on the web page.
; The "4" in {TAB 4} sends 4 tabs.
; So, +{TAB 4} sends 4 "back-tabs" - if you will allow me that term.
; In this case, it puts the "IE cursor" into "Yahoo! ID:" field.
; The last {TAB} puts the "IE cursor" into "Password:" field.


;Just some more painfully obvious notes - if you are still awake:

; If you want to "see" more of what the script does,
; slow the loops down by changing this line of code: Sleep(50)
; to Sleep(500)
; Then turn "ON" the Status Bar within IE - if it is OFF.
; (From the IE Menu bar, select "View".
; If there is already a check mark to the left of the term
; "Status Bar", then consider it to be "ON". If there is no check
; by the term "Status Bar", then click on "Status Bar" to toggle
; the check mark.)

; Run this script and watch the text change in that status bar.


; Most of the AutoIt "Windows functions"
; (like WinWait and WinExists)
; use some or all of the window title,
; depending on the AutoItSetOption settings.

; If more than one window has the same title, you can tell
; AutoIt to look for some "text" in the window to match also.
; FOR IE, THIS IS NOT TEXT FROM THE WEB PAGE.

; For IE, this "text" can be what shows in the status bar.
; Sometimes the text in the IE status bar is longer
; than can be seen in the IE window.
; Use the "AutoIt Window Info" tool to see it all.

; Now is where I'll talk about this line:
AutoItSetOption("WinDetectHiddenText", 1)
; If you can see the IE Status Bar (if it is "ON"),
; then AutoIt considers it to be "Visible Window Text"
; and it can be seen by the "AutoIt Window Info" tool under:
; >>>>>>>>>>> Visible Window Text <<<<<<<<<<<

; If the IE Status Bar is hidden (if it is "OFF"),
; then AutoIt considers it to be "Hidden Window Text"
; and it can be seen by the "AutoIt Window Info" tool under:
; >>>>>>>>>>> Hidden Window Text <<<<<<<<<<<

; To see if you can locate some "Window Text" that
; is unique to the link that you are searching for:
; 1. Start the "AutoIt Window Info" tool.
; 2. Manually surf to the web page of interest.
; 3. Tab until you see that the link is highlighted.
; (Highlighted in my IE puts dashed lines around the link.)
; 4. Press CTRL-ALT-F to pause the display
;    of the "AutoIt Window Info" tool.
; 5. COPY AND PASTE part (or all) of the link
;    FROM the "AutoIt Window Info" tool
;    TO your script.
; NOTE: You can avoid steps 4 and 5 if the
;       right-mouse-click menu (Copy Shortcut)
;       is enabled on the web page.

; This is the link that I "looped for" on the web page:
; cut off>>> /reg/login1/suli/forgot_lib <<<cut off

; I intentionally did not bring "StatusbarGetText" into this
; script/discussion. You can read about it if you wish.

;The END
Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites



Good Job, It might be worth knowing that ctrl + Tab will always tab to the address bar. (Or atleast it does for me)

The reason I bring this up is because a few months back I had a web page that wasnt always giving focus to the same control when It loaded. I dont know if it was because of IE or the webpage but it drove me nuts.

Anyway good job on the post. I personally use com now but thats only because I have a need to understand it.

Share this post


Link to post
Share on other sites

Good Job, It might be worth knowing that ctrl + Tab will always tab to the address bar. (Or atleast it does for me)...

<{POST_SNAPBACK}>

Thanks for the comments. You are correct, Ctrl-Tab works for me as well. (Also Atl-d)

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

CTRL Tab will only work if there is not a frame in the page.

ALT D works.

F6 also works.


Who else would I be?

Share this post


Link to post
Share on other sites

See carlgerman.com/jquery/hello-world for a downloadable au3 project and library here: autoIT IE browser automation

The scripts use the ability to inject javascript to automate the IE browser.

This script uses the autoIT IE COM library and that is why it is for IE browser automation only.

It is then a simple matter of using the BugBuster plugin for Chrome or plugin of your choice to get a unique CSS selector and the in-page JQuery helps in the background.

Share this post


Link to post
Share on other sites

CarlGerman,

This is the second time in 2 posts that you have necroed an old thread - and this one is nearly 10 years old! please do not do it again! :naughty:

And as those files are so small, why not post them directly? :huh:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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