Wheezer

Problem with IE

9 posts in this topic

Hello guys, i'm a rookie trying to create a script that logs me in to steam forums. After that it has to refresh every x seconds.

But there is a problem, whenever i run the script it says variable not declared.

Can somebody please help me out?

 

#include <ie.au3>
#include <MsgBoxConstants.au3>

Call ("internetexist")

Func internetexist()
If WinExists("Steam Community - Internet Explorer") Or WinExists("Rocket League Ruilen :: Steam Community - Internet Explorer") Then
    MsgBox($MB_SYSTEMMODAL, "IE", "Found it.")
    Call("Logn")
Else
Global $oIE = _IECreate("https://steamcommunity.com/login/home/?goto=app%2F252950%2Ftradingforum%2F"); i declared $oIE here, but...
Call("Logn")
        EndIf
EndFunc

Func Logn()
;Global $oIE = _IECreate("https://steamcommunity.com/login/home/?goto=app%2F252950%2Ftradingforum%2F");if i remove this line it gives "Variable used without being declared." why??
Global $oIEA = _IEAttach("", "instance", 1)
Global $user = _IEGetObjByName ($oIE, "username")
Global $pass = _IEGetObjByName ($oIE, "password")
_IEFormElementSetValue ($user, "test")
_IEFormElementSetValue ($pass, "****")
Global $oSubmit = _IEGetObjById($oIE, "SteamLogin")
Global $clicklogin = _IEAction($oSubmit, "Click")
Sleep(2000)
EndFunc

While 1
    Sleep(10000)
    ConsoleWrite("Refreshing")
    _IEAction($oIE, "refresh")
WEnd

"C:\Users\X\Desktop\autoit\trading rl BIJNA.au3" (19) : ==> Variable used without being declared.:
Global $user = _IEGetObjByName ($oIE, "username")
Global $user = _IEGetObjByName (^ ERROR

Share this post


Link to post
Share on other sites



try to declare Global $oIE outside the function (just before the Call ("internetexist")) and remove the "Global" statement from within the function.


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

It's no good codind practice to declare Globaal variable in a func. Try it this way:

#include <ie.au3>
#include <MsgBoxConstants.au3>

Global $oIE

Call("internetexist")

Func internetexist()
    If WinExists("Steam Community - Internet Explorer") Or WinExists("Rocket League Ruilen :: Steam Community - Internet Explorer") Then
        MsgBox($MB_SYSTEMMODAL, "IE", "Found it.")
        $oIE = _IEAttach("", "instance", 1)
        Call("Logn")
    Else
        $oIE = _IECreate("https://steamcommunity.com/login/home/?goto=app%2F252950%2Ftradingforum%2F")
        Call("Logn")
    EndIf
EndFunc   ;==>internetexist

Func Logn()
    Local $user = _IEGetObjByName($oIE, "username")
    Local $pass = _IEGetObjByName($oIE, "password")
    _IEFormElementSetValue($user, "test")
    _IEFormElementSetValue($pass, "****")
    Local $oSubmit = _IEGetObjById($oIE, "SteamLogin")
    Local $clicklogin = _IEAction($oSubmit, "Click")
    Sleep(2000)
EndFunc   ;==>Logn

While 1
    Sleep(10000)
    ConsoleWrite("Refreshing")
    _IEAction($oIE, "refresh")
WEnd

 

Share this post


Link to post
Share on other sites

This works! Thank you guys :)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

When I run your script with the line uncommented, it doesn't generate an error for me.

Edited by VeryGary

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

6 hours ago, VeryGary said:

When I run your script with the line uncommented, it doesn't generate an error for me.

Haven't you read?

 

On 17.9.2016 at 9:49 PM, Wheezer said:
Func Logn() 
;Global $oIE = _IECreate("https://steamcommunity.com/login/home/?goto=app%2F252950%2Ftradingforum%2F");if i remove this line it gives "Variable used without being declared." why??

 

 

Edited by AutoBert

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Hey guys,

I'm encountering a new problem, i have to click a button on the site.

When i search for the object Id, it's not there.

Look:

<a class="btn_darkblue_white_innerfade btn_medium responsive_OnClickDismissMenu" href="javascript:Forum_CreateTopic( 'Trading_9036925' );">
<span>          Een nieuwe discussie starten                </span></a>

My unfinished code:

Local $oTopic = _IEGetObjById($oIE, "$???") ;get the topic button
Local $oclicktopic = _IEAction($???, "Click");  click it

Is there a way to tackle this problem?

Edited by Wheezer

Share this post


Link to post
Share on other sites

Edit: If I run the code with the line uncommented or not, it doesn't generate an error for me.

Share this post


Link to post
Share on other sites
12 hours ago, VeryGary said:

Edit: If I run the code with the line uncommented or not, it doesn't generate an error for me.

Then you don't tested it with a already running instance from IE

 

On 17.9.2016 at 9:49 PM, Wheezer said:

 

...
Global $oIEA = _IEAttach("", "instance", 1)
Global $user = _IEGetObjByName ($oIE, "username")
...

 

.

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

  • Similar Content

    • ChipConnJohn
      By ChipConnJohn
      Hello all,
      Here's a cleaned up version of my code:
      #include <IE.au3>
      #include <MsgBoxConstants.au3>
      #include <Array.au3>
      #include <String.au3>
      ;#include <ErrorHandler.au3>
      ; Open Greatsite.com
      Global $oIE = _IECreate ("http://www.greatsite.com")
      ; I'm logged in and on the forum page.  Now to navigate categories with unknown names.
      ; Grab all links on page, then only dive into the ones with the text "forum_id="
      ; as in ?bview=forum&forum_id=108343
      Global $oLinksCategoryPage = _IELinkGetCollection($oIE)
      Local $iNumLinks = @extended
              ;Now at the thread level. Navigate into each thread and look at timestamp
              Global $oLinksOfThreads = _IELinkGetCollection($oIE)
              For $oLinkThread In $oLinksOfThreads
                  If StringInStr($oLinkThread.href,"thread_id") Then
                      _IENavigate($oIE, $oLinkThread.href)
                      ;Need to find instance of Posted and read text after the href.
                      Local $sBodyText = _IEBodyReadText($oIE)
                      ;Find first instance of the word "Posted" and check the two words to the right of it.
                      Local $aArrayOfBodyText = _StringExplode($sBodyText," ",0)
                      ;_ArrayDisplay($aArrayOfBodyText, "The body text in Array form")
                      ;Local $iIndexOfPosted = _ArraySearch($aArrayOfBodyText,"days")
                      For $iIndex = 0 to ubound($aArrayOfBodyText) - 1
                          If StringInStr(StringLower($aArrayOfBodyText[$iIndex]), "posted") Then
                              ;The word Posted has been found. Look for "Just A moment ago", "minutes", and "minute"
                              Select
                                  Case StringLower($aArrayOfBodyText[$iIndex +1]) = "just"
                                      ;"Just a moment ago.  Grab this one.
                                  Case Stringlower($aArrayOfBodyText[$iIndex +2]) = "minute"
                                      ;"1 minute". Grab this one
                                  Case Stringlower($aArrayOfBodyText[$iIndex +2]) = "minutes"
                                      ;"x minutes. Grab this one
                              EndSelect
                              ;ExitLoop ;Found the first one.  I'm done.
                          EndIf
                      ;Need to back out to Threads in Category
                      Next
                      _IEAction($oIE,"back")
                  EndIf
              Next
              ;Back out to Category List
              _IEAction($oIE,"back")
          EndIf
      Next
      _IEQuit($oIE)
       
      The script works fine until I hit the Next to go back to the For $oLinkThread In $oLinksOfThreads.  Any line that I put after that crashes with an error.  It's like the For loop is going one too many iterations and there is no object in the variable.
      The requested action with this object has failed.:
      If StringInStr($oLinkThread.href,"thread_id") Then
      If StringInStr($oLinkThread^ ERROR
      Thanks,
      -John
       
    • Lights_On
      By Lights_On
      Hi All,
      Below is an example of my code that will reproduce an issue I am having, all be it an issue that sometimes occurs and sometimes does not.
      #include <WinAPI.au3> #include <IE.au3> #include <MsgBoxConstants.au3> #include <Array.au3> Call ("Project") Func Project() Local $WaitTime = 10000 ; Set the time between checks in miliseconds While 1 $hwnd = WinGetHandle("[active]") If Not @error Then ; Ensure 'WinGetHandle' worked. Local $WinClassName = _WinAPI_GetClassName($hwnd) If $WinClassName = "IEFrame" Then ; If the curent window is an IE exploere instance then... Local $Object = _IEAttach($hwnd, "embedded") If not @error Then Local $url = _IEPropertyGet($Object, 'locationurl') If not @error Then Local $Split = StringSplit($url, "/") If $Split[0] > 2 Then ; This stops an error if the array did not have enought rows e.g no url to display form row 3. If Not $Split[3] = "" Then ; Dont bother if no url e.g blank msgbox(0, "URL is:", $Split) EndIf EndIf EndIf EndIf EndIf EndIf Sleep($WaitTime) WEnd EndFunc The issue is from IE.au3 and the error message is attached.  I am able to reproduce it is I run the scrip, load an instance of IE, then navigate to a different page such as google or something.
       
      I have looked in the code for IE.au3 and it reference to a function “__IEControlGetObjFromHWND(ByRef $hWin)” however I am not using this function so am a little unsure why or how this error is being called or what I can do to stop it?
       
      Any advice / help would be gratefully appreciated.
      Thank you.

    • kevin42036
      By kevin42036
      Hi All,

      I am very new to AutoIt and scripting in general and have a question about IEFormGetObjByName. The help function says:
      _IEFormGetObjByName ( ByRef $oObject, $sName [, $iIndex = 0] )
      But how do I find what to enter for $sName? In the example below, it says that it can be found by viewing the HTML source. So I went to the google home page, clicked Ctrl U to view the source, and cant figure out how they determined that the $sName is 'gbqf'. Can someone explain this process to me? Thanks in advance!
      ; Get a reference to a specific form by name.  In this case, submit a query
      ; to the Google search engine.  Note that the names of the form and form
      ; elements can be found by viewing the page HTML source
      #include <IE.au3>
      Local $oIE = _IECreate("http://www.google.com")
      Local $oForm = _IEFormGetObjByName($oIE, "gbqf")
      Local $oQuery = _IEFormElementGetObjByName($oForm, "q")
      _IEFormElementSetValue($oQuery, "AutoIt IE.au3")
      _IEFormSubmit($oForm)
       
    • jonson1986
      By jonson1986
      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[0]) _ArrayDelete($lines,"1-" & _ArraySearch($lines,$tag,1,0,0,1,1)) $lines[0]=UBound($lines)-1 _ArrayDisplay($lines)  
    • smellyfingers
      By smellyfingers
      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?