Jump to content

Recommended Posts

Posted

How do i exit from a while loop when a window exists ?

I tried do until Winexist("Confirm Exit") but still it isnt exiting. I tried below as well but it isnt working. Can anyone please help ?


 

#include <Constants.au3>
#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>

If $CmdLine[0] <> 2 Then
   MsgBox($MB_OK, "Usage", "saphana <username> <password>")
Else
   saphana($CmdLine[1], $CmdLine[2])
EndIf

Global $sData
Func saphana($username, $password)


Global $spid = Run("C:\Program Files\sap\hdbstudio\hdbstudio.exe")
MsgBox($MB_OK, "Usage", "script"&$spid,2,"")
Global $flag = 1
Global $PID = WinWait("hdbstudio - SAP HANA Administration Console - SAP HANA Studio")
Local $lpid = ProcessExists($spid)
MsgBox($MB_OK, "Usage", "script2"&$lpid,2,"")

While $flag = 1

 MsgBox($MB_OK, "Usage", "script3"&$PID,2,"")

$hwnd = WinWait("Database User Logon -")

   ; Ensure we are in the Username fieldm
   ; Send the instance

ControlFocus($hWnd, "", "Edit1")
ControlClick($hWnd, "", "Edit1", "left", 2,"","")
Send("^c") ;Copy selected text.
$sData = ClipGet() ;Retrieves text from clipboard.
$PID = WinWait("hdbstudio - SAP HANA Administration Console - SAP HANA Studio")
Local $cmp= StringCompare($sData,$username)

 If $cmp = 0 Then

    Send("{TAB}")
   ; Ensure we are in the Password field
   ; Send the Password
   Send($password, 1)
   ; Submit the credentials
   Send("{ENTER}")

ElseIf WinExists ("Confirm Exit") Then
   ExitLoop

Else
   MsgBox($MB_OK, "Usage", "Not allowed to access",2,"")
   WinWaitClose($hwnd)
EndIf


WEnd

WinWaitClose($hwnd)

EndFunc ;==>saphana()

 

Posted

Oh okay, so I do the if cmp =0 and the else not allowed to access- a separate if else. Then a separate' if 'for win exists? So the' if win exists' should return a true value if the window exists right? It can be used in a if statement. Okay ll test n see

Posted
17 hours ago, BigDaddyO said:

put the "WinExists ("Confirm Exit") Then" into it's own If statement.  If the $cmp = 0 then it will never check the ElseIf

 

no it isnt working still...it isnt detecting the window Handle .This is the window and i used the autoitinfo tool and it is detecting but still in the loop , its nt working. I want to exit the loop when the application stops running.I tried processexist in the do until condition and nothing, it is still not exiting.Can anyone please help. It is SAP hana studio client.

image.png.7b5dbbfc99f1f21f4f897aebd528000b.png

Posted

I think it is your while logic that is not working.  You should check credentials and if un/pw are right then start looping until the window (Confirm Exit) appears...So remove your while where it is currently. And replace it by something like :

do
  Sleep (500)
until WinExists ("Confirm Exit")

BTW Win* () (in your case it is winwait) does not return a pid, but window handle...Make sure that WinExists detects that exit window !

 

Posted
On 1/29/2019 at 6:09 PM, Nine said:

I think it is your while logic that is not working.  You should check credentials and if un/pw are right then start looping until the window (Confirm Exit) appears...So remove your while where it is currently. And replace it by something like :

do
  Sleep (500)
until WinExists ("Confirm Exit")

BTW Win* () (in your case it is winwait) does not return a pid, but window handle...Make sure that WinExists detects that exit window !

 

The thing is I need to send the username and password only if it detects another window and that window if prompted, I check the username that's in it and if the username matches with what's being passed, then I pass credential and it logs in.  And if username is nt same, then it gives out a message.  And whenever the user choose the sap Hana tenant, it should do the above and once confirm exit window is seen, it has to get out of the loop. And I am nt able to detect that window at all, I dno how to make it detect.

Posted (edited)
11 hours ago, Nine said:

Can you show us what Au3Info tool says about this window ?

Hi Nine

 

Below is the screenshot :-
 

Untitled picture.png

 

I tried with the text inside the confirm Exit window as well but it doesnt seem to work. Should i put the title in a variable and then use that variable in Winexists ?

 

Thank you for taking the time.

Edited by Drac89
Posted
4 hours ago, Drac89 said:

Should i put the title in a variable and then use that variable in Winexists ?

Doesn't matter, it will not change the result.  Now we know that the title of the Window is right.  So it must be your code logic that is causing not to work.  To debug it, I suggest you put multiple msgbox everywhere and follow the path of your logic.

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
  • Recently Browsing   0 members

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