Sign in to follow this  
Followers 0
joeloyzaga

get all tags with browser prompt

20 posts in this topic

the code below gets me all the tag innertexts for the url

Is it possible to just do this with the current active browser? It would be wonderful if I got to choose from whatever browsers are currently on the desktop so as not to create the instance every time - because sometimes I need to logon and navigate to the page I want to use....

Thanks

Joe

#include <IE.au3>
$oIE = _IECreate ("http://www.google.com")
$oElements = _IETagNameAllGetCollection ($oIE)
$oExcel = ObjCreate("Excel.Application")
$oExcel.Visible = True
$oExcel.Workbooks.add
$oExcel.ActiveWorkbook.Sheets(1).Cells(1, 1).Value = "Tag Name"
$oExcel.ActiveWorkbook.Sheets(1).Cells(1, 2).Value = "Inner Text"
$RowNumber =2
For $oElement In $oElements
   $oExcel.ActiveWorkbook.Sheets(1).Cells($RowNumber, 1).Value = $oElement.tagname
   $oExcel.ActiveWorkbook.Sheets(1).Cells($RowNumber, 2).Value = $oElement.innerText
   $RowNumber = $RowNumber + 1
Next

Share this post


Link to post
Share on other sites



It would be wonderful if I got to choose from whatever browsers are currently on the desktop so as not to create the instance every time....

Use _IEAttach() to get the reference to an existing browser.

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Use _IEAttach() to get the reference to an existing browser.

:D

$oIE = _IECreate ("http://www.google.com")

would change to

$oIE = _IEAttach()

??????????????????

Share this post


Link to post
Share on other sites

Not all browsers have a interface that AutoIt can interact with. Only internet explorer has one always, and Firefox can be configured or something. You need to use seperate libraries for each of the browsers. There is no universal browser control system.

Share this post


Link to post
Share on other sites

$oIE = _IECreate ("http://www.google.com")

would change to

$oIE = _IEAttach()

??????????????????

Demo:
#include <IE.au3>

; NOT saving the object reference
_IECreate("http://www.google.com")

Sleep(1000)

; Get reference to already existing instance of IE
$oIE = _IEAttach("http://www.google.com", "url")
_IENavigate($oIE, "http://www.autoitscript.com")

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Demo:

#include <IE.au3>

; NOT saving the object reference
_IECreate("http://www.google.com")

Sleep(1000)

; Get reference to already existing instance of IE
$oIE = _IEAttach("http://www.google.com", "url")
_IENavigate($oIE, "http://www.autoitscript.com")

:D

Psalty, just a fyi:

It would be wonderful if I got to choose from whatever browsers are currently on the desktop so as not to create the instance every time

The way I read it this can also mean that Firefox, Chrome, Opera, Safari, etc. can be on the desktop. Not just IE.

Share this post


Link to post
Share on other sites

The way I read it this can also mean that Firefox, Chrome, Opera, Safari, etc. can be on the desktop. Not just IE.

Yeah, I saw that. You were right on when you pointed out there was no universal browser UDF.

But the only direct answer with AutoIt is with IE.au3, and he specifically asked for an example using _IEAttach().

Cheers!

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

so when I run this - I still have to give it the url I want it to use? not just find the browser on the desktop and then dump the tags?

its only for IE and 1% firefox so could that be the case?

putting the url in will do fine - just wondering if its possible and how to so I can try it...

Joe

Share this post


Link to post
Share on other sites

the code below gets me all the tag innertexts for the url

Is it possible to just do this with the current active browser? It would be wonderful if I got to choose from whatever browsers are currently on the desktop so as not to create the instance every time - because sometimes I need to logon and navigate to the page I want to use....

Thanks

Joe

#include <IE.au3>
$oIE = _IECreate ("http://www.google.com")
$oElements = _IETagNameAllGetCollection ($oIE)
$oExcel = ObjCreate("Excel.Application")
$oExcel.Visible = True
$oExcel.Workbooks.add
$oExcel.ActiveWorkbook.Sheets(1).Cells(1, 1).Value = "Tag Name"
$oExcel.ActiveWorkbook.Sheets(1).Cells(1, 2).Value = "Inner Text"
$RowNumber =2
For $oElement In $oElements
   $oExcel.ActiveWorkbook.Sheets(1).Cells($RowNumber, 1).Value = $oElement.tagname
   $oExcel.ActiveWorkbook.Sheets(1).Cells($RowNumber, 2).Value = $oElement.innerText
   $RowNumber = $RowNumber + 1
Next

So I recorded the navigation to the page (will improve it when I get the next part working ) and added the code above and all I want to do is to be able to get the hwnd of the page I've navigated to sp as to run the get element script - does this make more sense? (any loss of clarity is due to my actually not understanding my own requirements....)

#region --- ScriptWriter generated code Start ---
Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
WinWait("Program Manager","")
If Not WinActive("Program Manager","") Then WinActivate("Program Manager","")
WinWaitActive("Program Manager","")
MouseClick("left",37,330,2)
WinWait("NSW Department of Education and Training Intranet Home Page - Windows Internet Explorer provided by ITD DET NSW","")
If Not WinActive("NSW Department of Education and Training Intranet Home Page - Windows Internet Explorer provided by ITD DET NSW","") Then WinActivate("NSW Department of Education and Training Intranet Home Page - Windows Internet Explorer provided by ITD DET NSW","")
WinWaitActive("NSW Department of Education and Training Intranet Home Page - Windows Internet Explorer provided by ITD DET NSW","")
MouseMove(62,491)
MouseDown("left")
MouseUp("left")
#endregion --- ScriptWriter generated code End ---


#region --- ScriptWriter generated code Start ---
Opt("WinWaitDelay",500)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
WinWait("e-Services : Home Page - Windows Internet Explorer provided by ITD DET NSW","")
If Not WinActive("e-Services : Home Page - Windows Internet Explorer provided by ITD DET NSW","") Then WinActivate("e-Services : Home Page - Windows Internet Explorer provided by ITD DET NSW","")
WinWaitActive("e-Services : Home Page - Windows Internet Explorer provided by ITD DET NSW","")
MouseMove(273,19)
MouseDown("left")
MouseUp("left")
MouseMove(279,256)
MouseDown("left")
MouseUp("left")
Opt("WinWaitDelay",500)

WinWait("e-Services : Logon - Windows Internet Explorer provided by ITD DET NSW","")
If Not WinActive("e-Services : Logon - Windows Internet Explorer provided by ITD DET NSW","") Then WinActivate("e-Services : Logon - Windows Internet Explorer provided by ITD DET NSW","")
WinWaitActive("e-Services : Logon - Windows Internet Explorer provided by ITD DET NSW","")
Send("jloyzaga1{TAB}celeste4")
MouseMove(758,296)
MouseDown("left")
MouseUp("left")
WinWait("Microsoft Internet Explorer","")
If Not WinActive("Microsoft Internet Explorer","") Then WinActivate("Microsoft Internet Explorer","")
WinWaitActive("Microsoft Internet Explorer","")
Opt("WinWaitDelay",3000)

MouseMove(157,110)
MouseDown("left")
MouseUp("left")
WinWait("e-Services : Home Page - Windows Internet Explorer provided by ITD DET NSW","")
If Not WinActive("e-Services : Home Page - Windows Internet Explorer provided by ITD DET NSW","") Then WinActivate("e-Services : Home Page - Windows Internet Explorer provided by ITD DET NSW","")
WinWaitActive("e-Services : Home Page - Windows Internet Explorer provided by ITD DET NSW","")
MouseMove(125,159)
MouseDown("left")
MouseUp("left")
MouseMove(164,243)
MouseDown("left")
MouseUp("left")
#endregion --- ScriptWriter generated code End ---

#region --- ScriptWriter generated code Start ---
Opt("WinWaitDelay",1000)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
WinWait("e-Services : Course Offering Status Maintenance - Windows Internet Explorer provided by ITD DET NSW","")
If Not WinActive("e-Services : Course Offering Status Maintenance - Windows Internet Explorer provided by ITD DET NSW","") Then WinActivate("e-Services : Course Offering Status Maintenance - Windows Internet Explorer provided by ITD DET NSW","")
WinWaitActive("e-Services : Course Offering Status Maintenance - Windows Internet Explorer provided by ITD DET NSW","")
MouseMove(268,19)
MouseDown("left")
MouseUp("left")
MouseMove(613,169)
MouseDown("left")
MouseUp("left")
#endregion --- ScriptWriter generated code End ---
#include <IE.au3>
$oIE = _IECreate ("http://www.google.com")
$oElements = _IETagNameAllGetCollection ($oIE)
$oExcel = ObjCreate("Excel.Application")
$oExcel.Visible = True
$oExcel.Workbooks.add
$oExcel.ActiveWorkbook.Sheets(1).Cells(1, 1).Value = "Tag Name"
$oExcel.ActiveWorkbook.Sheets(1).Cells(1, 2).Value = "Inner Text"
$RowNumber =2
For $oElement In $oElements
   $oExcel.ActiveWorkbook.Sheets(1).Cells($RowNumber, 1).Value = $oElement.tagname
   $oExcel.ActiveWorkbook.Sheets(1).Cells($RowNumber, 2).Value = $oElement.innerText
   $RowNumber = $RowNumber + 1
Next

Share this post


Link to post
Share on other sites

I'm sure I saw a thread that used a mouse point to select the browser to use??

Share this post


Link to post
Share on other sites

So I recorded the navigation to the page (will improve it when I get the next part working ) and added the code above and all I want to do is to be able to get the hwnd of the page I've navigated to sp as to run the get element script - does this make more sense? (any loss of clarity is due to my actually not understanding my own requirements....)

You can get the handle of the IE window with _IEPropertyGet() using "HWND".

...still haven't bothered to read the help file and try the many _IE* example scripts?

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

You can get the handle of the IE window with _IEPropertyGet() using "HWND".

...still haven't bothered to read the help file and try the many _IE* example scripts?

:D

now that I know what I'm looking for I'll try the examples

having found the hwnd will the examples show me how to use this to run the script?

Share this post


Link to post
Share on other sites

now that I know what I'm looking for I'll try the examples

having found the hwnd will the examples show me how to use this to run the script?

Perhaps you are misunderstanding some terminology. A web page does not have an HWND, the parent browser window does. The page (or pages, in the case of tabs) are represented by COM objects (typically $oIE in AutoIt scripts).

The handle returned by _IEPropertyGet($oIE, "HWND") would be used to do things like move, hide, minimize, restore, or maximize the whole window, not for anything related to a particular web page.

The $oIE object is used to get other child object references like $oForm or a collection of all INPUT tags, or a particular element withing the page.

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Perhaps you are misunderstanding some terminology. A web page does not have an HWND, the parent browser window does. The page (or pages, in the case of tabs) are represented by COM objects (typically $oIE in AutoIt scripts).

The handle returned by _IEPropertyGet($oIE, "HWND") would be used to do things like move, hide, minimize, restore, or maximize the whole window, not for anything related to a particular web page.

The $oIE object is used to get other child object references like $oForm or a collection of all INPUT tags, or a particular element withing the page.

:D

so if I'm navigating through the page and I display another page then I have to attach to the new page using its hwnd before I can work on any object within this new page? is there a way I can use the mouse to point to the page I want to use? A piece of code that asks for me to point to the browser I want to work on? or at least give me a list of them active ones to select from? can this be done?

Joe (I'm 52 years mellow - quite drinkable actually)

Share this post


Link to post
Share on other sites

so if I'm navigating through the page and I display another page then I have to attach to the new page using its hwnd before I can work on any object within this new page?

If you have a reference to a page in IE already (i.e. $oIE) and navigate that same browser to another page, the $oIE reference is still valid and points to the new page. All the references under it to forms, frames and elements, will be replaced with the new ones.

is there a way I can use the mouse to point to the page I want to use? A piece of code that asks for me to point to the browser I want to work on? or at least give me a list of them active ones to select from? can this be done?

For IE it would be still be _IEAttach() if a new browser window was opened. For other browsers you're on your own. Your script would have to have specific detection and handling routines for each different browser you wanted to handle (Firefox, Opera, Chrome, etc.).

There is no way for AutoIt to filter through all the windows and figure out which ones are "browsers" without looking for particular attributes of particular browsers you are looking for.

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

If you have a reference to a page in IE already (i.e. $oIE) and navigate that same browser to another page, the $oIE reference is still valid and points to the new page. All the references under it to forms, frames and elements, will be replaced with the new ones.

For IE it would be still be _IEAttach() if a new browser window was opened. For other browsers you're on your own. Your script would have to have specific detection and handling routines for each different browser you wanted to handle (Firefox, Opera, Chrome, etc.).

There is no way for AutoIt to filter through all the windows and figure out which ones are "browsers" without looking for particular attributes of particular browsers you are looking for.

:D

I'm only looking at IE so if there is a way to list all the instances of IE with the title "e e-Services : .*" and then selecting which one to use - then it would solve all my issues - otherwise....

In this case another window is created while still having the old one exist. I'd like to delete that one and I did _IEQuit but seems not to have worked

tried using this to attach to the new window but how do I know it did it other than by working on it? what would show up on the debugger?

$oIE = _IEAttach ("e-Services : Home Page - Windows Internet Explorer provided by ITD DET NSW")

Edited by joeloyzaga

Share this post


Link to post
Share on other sites

I'm only looking at IE so if there is a way to list all the instances of IE with the title "e e-Services : .*" and then selecting which one to use - then it would solve all my issues - otherwise....

In this case another window is created while still having the old one exist. I'd like to delete that one and I did _IEQuit but seems not to have worked

tried using this to attach to the new window but how do I know it did it other than by working on it? what would show up on the debugger?

$oIE = _IEAttach ("e-Services : Home Page - Windows Internet Explorer provided by ITD DET NSW")

First, note that document title is the default search in _IEAttach(), and there is also a "WindowTitle" for IE window. That looks like a window title because of the "Windows Internet Explorer provided by ITD DET NSW" appended to the end of it:
#include <IE.au3>

Global $sWinTitle = "e-Services : Home Page - Windows Internet Explorer provided by ITD DET NSW"
Global $oIE = _IEAttach($sWinTitle, "Title") ; Try document title first (same as default)
IF @error = 0 Then
    MsgBox(64, "Success", "Found IE with matching document title.")
Else
    $oIE = _IEAttach($sWinTitle, "WindowTitle") ; Try window title
    If @error = 0 Then
        MsgBox(64, "Success", "Found IE with matching window title.")
    Else
        MsgBox(16, "Error", "Could not find IE matching either document or window title.")
        Exit
    EndIf
EndIf

Second, if there is more than one, you can enumerate by instance and check other properties:

#include <IE.au3>

Global $i = 0, $oIE

While 1
    $oIE = _IEAttach("", "Instance", $i + 1) ; Find by 1-based instance
    IF @error = 0 Then
        $i += 1
        ConsoleWrite($i & ":" & @TAB & "Document title = " & _IEPropertyGet($oIE, "Title") & @LF & _
                @TAB & "Window title = " & WinGetTitle(_IEPropertyGet($oIE, "HWND")) & @LF & _
                @TAB & "URL = " & _IEPropertyGet($oIE, "LocationURL") & @LF & _
                @TAB & "Visible = " & _IEPropertyGet($oIE, "Visible") & @LF) ; -1 = True for "Visible", 0 = False
    Else
        ExitLoop
    EndIf
WEnd
ConsoleWrite("Found a total of " & $i & " instances of IE." & @LF)

All the magic is in the help file.

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

First, note that document title is the default search in _IEAttach(), and there is also a "WindowTitle" for IE window. That looks like a window title because of the "Windows Internet Explorer provided by ITD DET NSW" appended to the end of it:

#include <IE.au3>

Global $sWinTitle = "e-Services : Home Page - Windows Internet Explorer provided by ITD DET NSW"
Global $oIE = _IEAttach($sWinTitle, "Title") ; Try document title first (same as default)
IF @error = 0 Then
    MsgBox(64, "Success", "Found IE with matching document title.")
Else
    $oIE = _IEAttach($sWinTitle, "WindowTitle") ; Try window title
    If @error = 0 Then
        MsgBox(64, "Success", "Found IE with matching window title.")
    Else
        MsgBox(16, "Error", "Could not find IE matching either document or window title.")
        Exit
    EndIf
EndIf

Second, if there is more than one, you can enumerate by instance and check other properties:

#include <IE.au3>

Global $i = 0, $oIE

While 1
    $oIE = _IEAttach("", "Instance", $i + 1) ; Find by 1-based instance
    IF @error = 0 Then
        $i += 1
        ConsoleWrite($i & ":" & @TAB & "Document title = " & _IEPropertyGet($oIE, "Title") & @LF & _
                @TAB & "Window title = " & WinGetTitle(_IEPropertyGet($oIE, "HWND")) & @LF & _
                @TAB & "URL = " & _IEPropertyGet($oIE, "LocationURL") & @LF & _
                @TAB & "Visible = " & _IEPropertyGet($oIE, "Visible") & @LF) ; -1 = True for "Visible", 0 = False
    Else
        ExitLoop
    EndIf
WEnd
ConsoleWrite("Found a total of " & $i & " instances of IE." & @LF)

All the magic is in the help file.

:D

Using your code and the help file I have gone a long way: logging on selecting an image, clicking on the link after the secondary page is created and closing that secondary page, coming back to the initial page ($oIE) and now wanting to select "APPS" from a weblist(name "OfferingTypeCodeField") - would this be a form and to select the value I'd use _IEFormElementOptionselect

would this be the code?

$oSelect = _IEFormElementGetObjByName ($oIE, "OfferingTypeCodeField")

_IEFormElementOptionselect ($oSelect, "APPS", 1, "byText")

Share this post


Link to post
Share on other sites

... now wanting to select "APPS" from a weblist(name "OfferingTypeCodeField") - would this be a form and to select the value I'd use _IEFormElementOptionselect

would this be the code?

$oSelect = _IEFormElementGetObjByName ($oIE, "OfferingTypeCodeField")

_IEFormElementOptionselect ($oSelect, "APPS", 1, "byText")

I assume you're asking because that DIDN'T work! :D

First thing that jumps out is using $oIE for the form reference. You might have to get a reference to the form it's in ($oForm, typically) and get the element reference from that. For example, if it's the first form on the page:

; Get form reference by index - might also be retrieved with _IEFormGetObjByName(), etc.
$oForm = _IEFormGetCollection($oIE, 0) ; First form (index = 0)

$oSelect = _IEFormElementGetObjByName($oForm, "OfferingTypeCodeField")
_IEFormElementOptionselect ($oSelect, "APPS", 1, "byText")

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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