9 posts in this topic
Hello I'm trying to translate few text using below code, I found it working previously couple of months ago but Now these days it's not working at all and I'm getting below errors when I run the script and Array display at the end of text also not able to show any translated text instead of value 0 & 1;
--> IE.au3 T3.0-2 Warning from function _IEGetObjById, $_IESTATUS_NoMatch (gt-res-data)
--> IE.au3 T3.0-2 Error from function _IEPropertyGet, $_IESTATUS_InvalidDataType
Here is code,
#include <IE.au3> #include <Array.au3> Local $tag="* # * # *" Local $oIE=_IECreate("https://translate.google.com/#auto/es") Local $oForm=_IEFormGetCollection($oIE,0) Local $oQuery=_IEGetObjByName($oForm,"text") _IEFormElementSetValue($oQuery, $tag & @CR & "Hello World" & @CR & "This is a test" & @CR & $tag) _IEFormSubmit($oForm) _IELoadWait($oIE) Local $oText=_IEGetObjById($oIE,"gt-res-data") $lines=StringSplit(_IEPropertyGet($oText,"innerText"),@CRLF,1) _IEQuit($oIE) _ArrayDelete($lines,_ArraySearch($lines,$tag,1,0,0,1,0) & "-" & $lines) _ArrayDelete($lines,"1-" & _ArraySearch($lines,$tag,1,0,0,1,1)) $lines=UBound($lines)-1 _ArrayDisplay($lines)
Hey, i hope someone can point me in the right direction, i have a page with tables, inside i have TD,TR,INPUT tags, the input tags is buttons and i need to click on one of theese buttons but they have the same value and type so the only way that i am going to know that it's the correct button is to find out the name of the innerhtml of the TD before (the parent node) because the input comes after, like this
<TABLE> <TR> <TD> Name of the td </TD> <TR> <TD colSpan=3<INPUT> value=my button type=button</INPUT></TD> <TR> <TD> Other name of a td </TD> <TR> <TD colSpan=3<INPUT> value=my button type=button</INPUT></TD> <TR> I know how to find all td's and inputs but not (in a loop) look for the td's and once it has found it click on the corresponding or "closest" input, maybe a nested loop?
I made a for loop using _IETagnameGetCollection($ie,"TD") and after it found the TD i tried looking for nextSibling but that might be impossible with INPUT perhaps?
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'm having some trouble with my script that scrapes out the content of iframes from pages using IE. On certain pages the script always fails , my fist thought was it was a timing issue so i tried adding Sleep(5000) in a few places and that doesn't appear to make any difference and it seems to always be the same pages so im not thinking its about timing.
The error in the console reads
"C:\Program Files (x86)\AutoIt3\Include\IE.au3" (2308) : ==> The requested action with this object has failed.: $oTemp = $oObject.document.body $oTemp = $oObject^ ERROR My code is as follows
#include <IE.au3> #include <MsgBoxConstants.au3> #include <Array.au3> #include <File.au3> #include <String.au3> Local $oIE = _IECreate("about:blank") $OriginalURL = "http://urbanikstreetdance-glasgow.co.uk/contact/3762801" _IENavigate($oIE, $OriginalURL) Local $oFrames = _IEFrameGetCollection($oIE) Local $iNumFrames = @extended If $iNumFrames > 0 Then Sleep(1000) Local $oFrame = 0 For $i = 1 To ($iNumFrames - 1) $oFrame = _IEFrameGetCollection($oIE, $i) ConsoleWrite(@error) $frame_html = _IEPropertyGet($oFrame, "innerhtml") & @CRLF If StringLeft($frame_html, 7) = "<iframe" Then ConsoleWrite(@CRLF & $OriginalURL & "|" & _IEPropertyGet($oIE, "locationurl") & $frame_html) EndIf Next EndIf Does anyone have any ideas on either how to stop it from failing or something i can do to identify that it will fail so i can exclude it from being checked.
Any help would be greatly appreciated