3 posts in this topic
Let's take a simple example to illustrate my case.
I open a webpage with the command _IECreate and I parse all its elements :
#include <IE.au3> $oIE = _IECreate("http://www.york.ac.uk/teaching/cws/wws/webpage1.html") $oElements = _IETagNameAllGetCollection($oIE) For $oElement In $oElements ConsoleWrite("Tagname: " & $oElement.tagname & @CRLF & "Id: " & $oElement.id & @CRLF & "InnerText: " & $oElement.innerText & @CRLF & "--------------------------------" & @CRLF) Next Now let's imagine I simulate a click with MouseClick to the link "lesson two" at the bottom of this webpage. A new webpage will open :
I'd like to get the elements (tagname, id, innertext) of this new webpage, just like I got them for the first webpage. But for this, I presume I would have to get a new $oIE2 Object variable of an InternetExplorer.Application, in order to be able to use the _IETagNameAllGetCollection once again.
How am I supposed to do this ?
Thank you !
I'm using the IE.au3 library to parse elements in a webpage and get their (x,y) coordinates.
Main commands I'm using are :
$oIE = _IECreate($myWebPage) $oElements = _IETagNameGetCollection($oIE, "label") $windowleft = $oIE.document.parentwindow.screenLeft $windowtop = $oIE.document.parentwindow.screenTop $oElementPosX = $windowleft + _IEfindPosX($oElement) $oElementPosY = $windowtop + _IEfindPosY($oElement) Now things become a bit tricky when i simulate a scroll in my webpage :
$oIE.document.parentwindow.scroll(0, $myScrollY) Because once this is done, the coordinates of the elements are still what they were before the scroll.
I can manage this problem by keeping track of the number of pixels I have scrolled, and compute the new "real" ($oElementPosX, $oElementPosY).
But I'm pretty sure there's a more efficient / more elegant way to do it.
What's more in some situations, when I click some controls in the webpage, the webpage adds new elements and shifts the controls below by a random number of pixel, so my workaround can't be used...
So here's my question : Is there a way to "refresh" the calculation of label coordinates ($oElementPosX, $oElementPosY) after a scroll ?
Thank you !
EDIT : I forgot to post the _IEfindPosX and _IEfindPosY functions (found somewhere on this forum) :
Func _IEfindPosX($o_object) Local $curleft = 0 Local $parent = $o_object If IsObj($parent) Then While IsObj($parent) $curleft += $parent.offsetLeft $parent = $parent.offsetParent WEnd Else Local $objx = $o_object.x If IsObj($objx) Then $curleft += $objx EndIf Return $curleft EndFunc Func _IEfindPosY($o_object) Local $curtop = 0 Local $parent = $o_object If IsObj($parent) Then While IsObj($parent) $curtop += $parent.offsetTop $parent = $parent.offsetParent WEnd Else Local $objy = $o_object.y If IsObj($objy) Then $curtop += $objy EndIf Return $curtop EndFunc
I am really stuck with this.
local $oIE = _IEAttach("Application") ; the name of Tab
local $oForm = _IEFormElementGetObjByName($oIE, "lastName") ; "lastName" - <input name="lastName" class...>
running it,, there is an error: _IEFormElementGetObjByName, $_TESTATUS_InvalidObjectType
I'm trying to save source of a particular webpage using its URL. When i tried to save source code using following command it works fine
$IE = _IECreate( 'www.example.com', 0, 0 )
But my problem is different I've saved different URL in my excel sheet, that's why, I tried to use "$IE" command in this way;
$URL = _Excel_RangeCopyPaste($oWorkbook1.Activesheet, "C1")
$IE = _IECreate($URL, 0, 0 )
But It's unable to fetch source codes using URL placed in excel sheet 1 at cell No. "C1".
Please guide me what's wrong with my codes and how can I make it possible to use URL placed in excel sheet instead of copying URL every time in "_IECreate" command.
#RequireAdmin #include <Excel.au3> #include <IE.au3> #include <String.au3> #include <Array.au3> Local $oExcel = _Excel_Open() Local $oWorkbook1 = _Excel_BookOpen($oExcel, @ScriptDir & "\Software.csv", True) $file = fileopen(@scriptdir & "\source01.txt", 10) ;------------Below Command is not working--------------------- $URL = _Excel_RangeCopyPaste($oWorkbook1.Activesheet, "C1" ;------------String $IE unable to fetch data from URL available in excel sheet at cell No. "C1"--------------------- $IE = _IECreate($URL, 0, 0 ) $source = _IEDocReadHTML($IE) FileWrite($file, $source)
My program is super simple with only 2 lines of code.
#include <IE.au3> $Site = _IECreate("www.google.com", 0, 1, 1) I'm just trying to open up a browser that goes to google.com
The issue with this is that whenever I try and run the program, I get this error
Not sure how to go about fixing this issue?