Jump to content
Sign in to follow this  
gspot

autoit javascript error

Recommended Posts

gspot

Hi!

Im trying to get an element from a page using javascript in autoit, searching the forum i didnt find much about the subject.

I tryed this simple example 

#include <IE.au3>
#include <MsgBoxConstants.au3>
Local $oIE, $oElem

$oIE = _IECreate("https://www.autoitscript.com/site/", 0, 0)
$oElem = $oIE.document.getElementsByTagName('p')[1].innerText
msgbox(0, "", $oElem)

In a javascript console document.getElementsByTagName('p')[1].innerText gives "AutoIt v3 is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting..."

But when i try in autoit it gives the error 

(6) : ==> Subscript used on non-accessible variable.:
$oElem = $oIE.document.getElementsByTagName('p')[1].innerText
$oElem = $oIE.document.getElementsByTagName('p')^ ERROR
 
Can someone help?
 

Share this post


Link to post
Share on other sites
gspot

Try

$oElem = $oIE.document.getElementsByTagName('p').innerText

 

Didnt work for me, no error, but doesnt return the text...

Share this post


Link to post
Share on other sites
bogQ

you need to check do  $oIE.document.getElementsByTagName('p') return array?


TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites
gspot

you need to check do  $oIE.document.getElementsByTagName('p') return array?

 

No.

Share this post


Link to post
Share on other sites
bogQ

$oElem = $oIE.document.GetElementsByTagName("p").item(1).innerText()


TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites
MikahS

#include <IE.au3>

#include <MsgBoxConstants.au3>

Local $oIE, $oElem

$oIE = _IECreate("https://www.autoitscript.com/site/", 0, 1, 1)
$oElem = $oIE.document.GetElementsByTagName("p").item(1).innerText()

MsgBox(0, "", $oElem)

EDIT: bogQ beat me to it ;)

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites
gspot

:thumbsup:  Thats it! thanks to all.

Share this post


Link to post
Share on other sites
trancexx

.innerText is property, not method. That means the last set of parentheses shouldn't be there.
Also, .item is default property, meaning it can be omitted:

$oIE.document.GetElementsByTagName("p")(1).innerText

...Disable buggy AU3Check before running that.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
bogQ

cheating.jpg

:)


TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

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  

×