Jump to content

Issue with previously working script


NoizeBit
 Share

Recommended Posts

Fellow Scripters,

Once again I'd like to ask for some assistance on a strange issue I've encountered recently. The snippet looks like this:

$tags = $oIE.document.GetElementsByTagName("div")
For $tag In $tags
    $class_value = $tag.GetAttribute("class")
    If $class_value = "gwt-HTML" Then
        $sCurrentBalance = $tag.innerText
            FileWriteLine($Balance_File, _NowDate() & @TAB & $sCurrentBalance)
        ExitLoop
    EndIf
Next

This was working correctly about a year ago, but now the command

FileWriteLine($Balance_File, _NowDate() & @TAB & $sCurrentBalance)

doesn't do anything and the variable $sCurrentBalance doesn't show it's value using MsgBox. Strangely, some calculations after this part do get the value of this variable and seems not to be affected by this problem.

Any thoughts, ideas? I was thinking about that upgrading AutoIt might have something to do with this, but after compiling using a previous version the issue remains nonetheless...

Edited by NoizeBit
Link to comment
Share on other sites

The site has not changed a bit, tags remain the same. Here's the full script:

#include <Date.au3>
#include <File.au3>
#include <IE.au3>

Global $oIE = _IECreate("https://www.bosscapital.com/app/?lang=EN#Trade", 0, 0, 1, 0)
Global $Broker_User = "xxx"
Global $Broker_Pass = "yyy"

Global $Balance_File = @ScriptDir & "\balance.txt"

CheckIfLoginBroker()
Sleep(5000)

Global $sCurrentBalance
Global $sPreviousBalance = GetPreviousBalance()

$tags = $oIE.document.GetElementsByTagName("div")
For $tag In $tags
    $class_value = $tag.GetAttribute("class")
    If $class_value = "gwt-HTML" Then
        $sCurrentBalance = $tag.innerText
            FileWriteLine($Balance_File, _NowDate() & @TAB & $sCurrentBalance)
        ExitLoop
    EndIf
Next

Global $iCurrentBalanceCalc = StringTrimLeft($sCurrentBalance, 1)
Global $iPreviousBalanceCalc = StringTrimLeft($sPreviousBalance, 1)
Global $iBalanceDifference = Round($iCurrentBalanceCalc - $iPreviousBalanceCalc, 2)
Global $iBalDiffPerc = Round($iBalanceDifference / $iPreviousBalanceCalc * 100, 2)

Global $iBalanceDifferenceAbs, $sSignBal
Global $iBalDiffPercAbs, $sSignPerc
Global $sTextColor

If $iBalanceDifference < 0 Then
    $iBalanceDifferenceAbs = StringTrimLeft($iBalanceDifference, 1)
    $sSignBal = "-"
    $sTextColor = "188, 14, 25"
ElseIf $iBalanceDifference > 0 Then
    $iBalanceDifferenceAbs = $iBalanceDifference
    $sSignBal = "+"
    $sTextColor = "111, 178, 56"
Else
    $iBalanceDifferenceAbs = $iBalanceDifference
    $sSignBal = ""
    $sTextColor = "251, 213, 57"
EndIf

If $iBalDiffPerc < 0 Then
    $iBalDiffPercAbs = StringTrimLeft($iBalDiffPerc, 1)
    $sSignPerc = "-"
ElseIf $iBalDiffPerc > 0 Then
    $iBalDiffPercAbs = $iBalDiffPerc
    $sSignPerc = "+"
Else
    $iBalDiffPercAbs = "0"
    $sSignPerc = ""
EndIf

_IEQuit($oIE)

Func GetPreviousBalance()
    $tempString = FileRead($Balance_File)
    If StringInStr($tempString, @TAB) < 1 Then Return 0
    Return StringTrimLeft($tempString, StringInStr($tempString, @TAB, 0, -1))
EndFunc   ;==>GetPreviousBalance

Func CheckIfLoginBroker() ;Look for login form on broker's site (active status)
    $tags = $oIE.document.GetElementsByTagName("input")
    $found = False
    For $tag In $tags
        $class_value = $tag.GetAttribute("class")
        If $class_value = "gwt-TextBox navigation_menu_username_field" Then
            $tag.click()
            $found = True
            ExitLoop
        EndIf
    Next
    If $found Then ;Login if login form is visible (inactive status)
        $tags = $oIE.document.GetElementsByTagName("input")
        $found = False
        For $tag In $tags
            $class_value = $tag.GetAttribute("class")
            If $class_value = "gwt-TextBox navigation_menu_username_field" Then
                _IEFormElementSetValue($tag, $Broker_User)
            EndIf
            If $class_value = "gwt-TextBox navigation_menu_password_field" Then
                _IEFormElementSetValue($tag, $Broker_Pass)
            EndIf
        Next
        $tags = $oIE.document.GetElementsByTagName("div")
        $found = False
        For $tag In $tags
            $class_value = $tag.GetAttribute("class")
            If $class_value = "navigation_menu_login_button" Then
                $tag.click()
                ExitLoop
            EndIf
        Next
        Sleep(5000)
        _IELoadWait($oIE)
    EndIf
EndFunc   ;==>CheckIfLoginBroker

 

Edited by NoizeBit
Link to comment
Share on other sites

11 minutes ago, NoizeBit said:

doesn't do anything and the variable $sCurrentBalance doesn't show it's value using MsgBox. Strangely, some calculations after this part do get the value of this variable and seems not to be affected by this problem.

If that's your full script in #3 then where does this part happen? I see one reference to $sCurrentBalance in your "full" script, so where is it referenced after that line in your real script?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

11 minutes ago, BrewManNH said:

If that's your full script in #3 then where does this part happen? I see one reference to $sCurrentBalance in your "full" script, so where is it referenced after that line in your real script?

You're right, edited my previous post with the full code, a part of it was missing from file I've copied from originally

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...