Not working Send() and Mouse Click in window with Class:SunAwtFrame on third level - autoit

I try to automate procedures in my Oracle MiddleWare Environment and when I get to the bottom of it, where I should click "Run" button (in Cyrrilic), I can't do this with Send, or Control, or Mouse. However, it is third level of the submenu, all other levels work (I know the usual problems with Frames, but it works for other levels, than why?))
The summary from Info is below:
Window <<<<
Title: My Window
Class: SunAwtFrame
Position: 0, 0
Size: 820, 660
Style: 0x16CF0000
ExStyle: 0x00000100
Handle: 0x00171058
Control <<<<
Class:
Instance:
ClassnameNN:
Name:
Advanced (Class):
ID:
Text:
Position:
Size:
ControlClick Coords:
Style:
ExStyle:
Handle: 0x000910F4
Mouse <<<<
Position: 448, 427
Cursor ID: 0
Color: 0xC0FFFF
StatusBar <<<<
ToolsBar <<<<
Visible Text <<<<
Hidden Text <<<<
Local $sLogin = InputBox("Security Check", "Enter your login", "")
Local $sPasswd = InputBox("Security Check", "Enter your password.", "","-")
$oIE = _IECreate("https://******************",0,0,1,1)
$oLinks = _IETagNameGetCollection($oIE, "input")
For $oLink In $oLinks
If String($oLink.type) = "button" And String($oLink.value) = "RUN" Then
_IEAction($oLink, "click")
ExitLoop
EndIf
Next
_IELoadWait($oIE, 1000)
Sleep(15000)
_WinWaitActivate("Oracle Fusion Middleware Forms Services","")
Send($sLogin)
Send("{TAB}")
Send($sPasswd)
Send("{TAB}")
Send("{SHIFTDOWN}prod{SHIFTUP}9{ENTER}")
_WinWaitActivate("My Window","")
Send("{TAB}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}
{DOWN}{UP}{RIGHT}{DOWN}{DOWN}{DOWN}{DOWN}{RIGHT}{DOWN}{DOWN}{RIGHT}{DOWN}
{DOWN}{DOWN}{DOWN}{DOWN}{RIGHT}{DOWN}{DOWN}{DOWN}{DOWN}{ENTER}")
*//And here it stops working without any error.//
Send("03/01/2019")
Send("{TAB}{TAB}{TAB}")
MouseMove(268,363,25)
MouseClick("primary")
Please note that I cannot change anything at all in Oracle MiddleWare environment or on the server side.

To answer this for your class SunAwtFrame the question is too unclear. But your code has some issues.
_WinWaitActivate() with Sleep(15000) isn't necessary because you can use WinWaitActive($sTitle, $sText, $iTimeout) with a timeout of 15 seconds as third parameter.
Your problem for the stopping should be the line 21. You can not add a new line within a function parameter without using of & _ at the end of the line. Use a function like _sendKeystrokesSeveralTimes() to avoid such long parameter values.
You also could shorten your MouseMove() and then MouseClick() action by doing MouseClick('left', 268, 363) to the target mouse position.
Here a reworked version of your code:
#include-once
#include <IE.au3>
Global $sLogin = InputBox('Security Check', 'Enter your login', '')
Global $sPasswd = InputBox('Security Check', 'Enter your password.', '', '-')
Global $oIE = _IECreate('https://******************', 0, 0, 1, 1)
Global $oLinks = _IETagNameGetCollection($oIE, 'input')
Func _clickButtonRun()
For $oLink In $oLinks
If String($oLink.type) == 'button' And String($oLink.value) == 'RUN' Then
_IEAction($oLink, 'click')
ExitLoop
EndIf
Next
EndFunc
Func _sendKeystrokesSeveralTimes($sKey, $iHowOften = 1)
For $i = 1 To $iHowOften Step 1
Send($sKey)
Sleep(200) ; to increase the robustness wait a bit between each input/send
Next
EndFunc
_clickButtonRun()
_IELoadWait($oIE, 1000)
WinWaitActive('Oracle Fusion Middleware Forms Services', '', 15)
_sendKeystrokesSeveralTimes($sLogin)
_sendKeystrokesSeveralTimes('{TAB}')
_sendKeystrokesSeveralTimes($sPasswd)
_sendKeystrokesSeveralTimes('{TAB}')
_sendKeystrokesSeveralTimes('PROD9')
_sendKeystrokesSeveralTimes('{ENTER}')
WinWaitActive('My Window', '', 5)
_sendKeystrokesSeveralTimes('{TAB}')
_sendKeystrokesSeveralTimes('{DOWN}', 11)
_sendKeystrokesSeveralTimes('{UP}')
_sendKeystrokesSeveralTimes('{RIGHT}')
_sendKeystrokesSeveralTimes('{DOWN}', 4)
_sendKeystrokesSeveralTimes('{RIGHT}')
_sendKeystrokesSeveralTimes('{DOWN}', 2)
_sendKeystrokesSeveralTimes('{RIGHT}')
_sendKeystrokesSeveralTimes('{DOWN}', 5)
_sendKeystrokesSeveralTimes('{RIGHT}')
_sendKeystrokesSeveralTimes('{DOWN}', 4)
_sendKeystrokesSeveralTimes('{ENTER}')
_sendKeystrokesSeveralTimes('03/01/2019')
_sendKeystrokesSeveralTimes('{TAB}', 3)
MouseClick('left', 268, 363)

Related

How in GUI to show the text from the file which changes?

In the file 1.txt in the first line there is an inscription, and it changes over time. In the GUI, it should also be changed. How to make it not flicker?
Local $Form1 = GUICreate('Form1', 261, 200, 192, 124)
$10 = FileReadLine ( "1.txt", 1);
GUISetState()
Local $spic = $10, $Pic1
While 1
$Pic1 = GUICtrlCreateLabel($10, 10, 70, 235, 50)
Switch FileExists($spic)
Case 0
If $Pic1 Then
GUICtrlDelete($Pic1)
$Pic1 = 0
EndIf
Case 1
If Not $Pic1 Then $Pic1 = GUICtrlCreatePic($spic, 16, 24, 212, 124)
EndSwitch
Sleep(1)
WEnd
#include <GUIConstantsEx.au3>
; Create the Gui.
$Form1 = GUICreate('Form1', 261, 200, 192, 124)
$iLabel = GUICtrlCreateLabel('', 10, 10, 235, 50)
$iPic = GUICtrlCreatePic('', 16, 34, 212, 124)
GUISetState()
; Hide picture control if no file [True|False].
$bHideImage = FileExists('default.jpg') ? False : True
; Updates in the loop to recognize change.
$sSavedFilename = ''
; Set time to reset image etc.
$iTimeReset = 1000
$hTimeStamp = TimerInit()
While 1
; Get Gui messages.
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
GUIDelete()
Exit
EndSwitch
; Check if time needs reset.
If TimerDiff($hTimeStamp) > $iTimeReset Then
$hTimeStamp = TimerInit()
Else
ContinueLoop
EndIf
; Read 1st line of a file.
$sReadFilename = FileReadLine ('1.txt', 1)
; If the saved line is different to read line.
If $sSavedFilename <> $sReadFilename Then
GUICtrlSetData($iLabel, $sReadFilename)
Switch FileExists($sReadFilename)
Case 0
If $bHideImage Then
GUICtrlSetState($iPic, $GUI_HIDE)
Else
; Display a default (blank?) image.
GUICtrlSetImage($iPic, 'default.jpg')
EndIf
Case 1
If $bHideImage Then
GUICtrlSetState($iPic, $GUI_SHOW)
EndIf
; Display the new image.
GUICtrlSetImage($iPic, $sReadFilename)
EndSwitch
; Save the current filename.
$sSavedFilename = $sReadFilename
EndIf
WEnd
Sleep is accurate to approximately
10 milliseconds, which is of so little time to update a control, thus
you get the flicker.
Update of labels which do not occur on an event like a button click,
can be handled using a timer.
If you use a message loop Gui, then you get the Gui messages with using
GuiGetMsg. After the messages, you can check a time stamp to know if
the time difference is larger than the time reset value which is currently
set as 1000 milliseconds. If larger, timer is reset and the code below
is executed, else will continue the loop from the top.
The filename read from the text file is saved to $sSavedFilename.
Updating of controls is only done when the read filename is different. If
the filename read does not exist, then display a default (blank?) image.
I sometimes choose a default image else an empty filename instead can
cause control sizing issues with the next image change. The control could
be instead be hidden, if no image to show. $bHideImage current decides
to use the file default.jpg if exist, else to hides the control.
This code updates the created controls instead of deleting and recreating them.
Update GUICtrlCreateLabel text with GUICtrlSetData.
Update GUICtrlCreatePic image with GUICtrlSetImage.

If statement not working AutoIT

I am having trouble with the code I am writing. I have a table which lists staff member details. I am trying to have an email address copy to the clipboard when you select a record and right click. I have the following code:
#include <GUIConstantsEx.au3>
#include <mssql.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>
global $title = "E-Mail address lookup"
global $name = InputBox($title,"Please type the name of the person you wish to find")
global $sqlCon = _MSSQL_Con("server", "username", "password", "directory-plus")
global $result = _MSSQL_GetRecord($sqlCon, "autoit_view","*", "WHERE cn LIKE '%" & StringStripWS($name,3) & "%'")
if StringLen(StringStripWS($name,3)) < 1 then
MsgBox(0, $title, "Name cannot be empty")
Else
Global $rset = UBound($result) - 1
Global $ControlID = GUICreate($title, 500, 150)
Global $idListview = GUICtrlCreateListView("Deparment|E-Mail Address|Name|Telephone Number", 10, 10, 480, 150)
for $count = 1 to $rset step 1
GUICtrlCreateListViewItem($result[$count][0] & "|" & $result[$count][2] & "|" & $result[$count][1] & "|" & $result[$count][2], $idListview)
if MouseClick($MOUSE_CLICK_RIGHT)==1 Then
ClipPut($result[$count][2])
EndIf
Next
GUISetState(#SW_SHOW)
GUISetState()
While 1
Global $Msg = GUIGetMsg()
Switch $Msg
Case -3, $ControlID
Exit
EndSwitch
WEnd
EndIf
I would have thought my IF statement within the for loop would do the trick but, when I run my code, it just copies whatever is in email address column in the last row when in fact I want it to copy the email address when you right click on a particular row but I'm not sure how to do it.
Your code has two major problems. The first is that MouseClick() doesn't check for the mouse button being pressed, but instead sends a mouse button click. Since sending a mouse button click is going to succeed, MouseClick($MOUSE_CLICK_RIGHT)==1 will evaluate to true. For each list view item you create, you are putting the email address on the clipboard.
The second problem is that the if statement is in the wrong place. It's executed just after you create each list view item.
Instead, change your While statement as follows
While 1
Global $Msg = GUIGetMsg()
Switch $Msg
Case -3, $ControlID
Exit
case $GUI_EVENT_SECONDARYDOWN
$selecteditem=StringSplit(GUICtrlRead(GUICtrlRead($idListview)),"|")
if #error=0 and $selecteditem[0]>1 Then
ClipPut($selecteditem[2])
EndIf
EndSwitch
WEnd

autoit3 - trigger context menu to open on button click/press

I am working on a project, in which I decided I should have history of previously searched stuff (since it's an app with which you can search stuff), so I have been thinking that I could just create the context menu or regular menu, that I could somehow force to activate on a button click or by using accelerators.
Now, I haven't been able to figure out how to make that work.
First I tried the GuiCtrlSetState() function, which didn't seem to work (I tried show and focus), then I tried accelerators and they didn't do anything.
So I'm wondering is there any way I can make the context menu or regular menu pop up on button press/click or key press (with accelerators)?
So what I'm basically trying to do is some sort of a pop-up, you click on a button or press a key to trigger the context menu or regular menu to open.
I know I could be old school and use a new GUI or just a combo box for the history or anything but I kinda want this, if there's any way to do so.
Any help, or an alternative way of doing the same thing appreciated.
Here's the testing code in which I was trying to make the test button trigger and activate the context menu, and I have tried the same with the regular
menu: 
#NoTrayIcon
#include <GUIConstantsEx.au3>
GUICreate("test123")
$but = guictrlcreatebutton("test", -1, -1, -1)
$xt = GUICtrlCreateContextMenu("test context menu")
GUICtrlCreateMenuItem("test1", $xt)
GUICtrlCreateMenuItem("test2", $xt)
GUISetState(#SW_MAXIMIZE)
While 1
$msg = GUIGetMsg()
If $msg = $but Then
GUICtrlSetState($xt, $GUI_FOCUS)
EndIf
Sleep(5)
WEnd
If you check the help file under GUICtrlCreateContextMenu:
; right click on gui to bring up context Menu.
; right click on the "ok" button to bring up a controll specific context menu.
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
Example()
Func Example()
GUICreate("My GUI Context Menu", 300, 200)
Local $idContextmenu = GUICtrlCreateContextMenu()
Local $idNewsubmenu = GUICtrlCreateMenu("new", $idContextmenu)
Local $idNewsubmenuText = GUICtrlCreateMenuItem("text", $idNewsubmenu)
Local $idButton = GUICtrlCreateButton("OK", 100, 100, 70, 20)
Local $idButtoncontext = GUICtrlCreateContextMenu($idButton)
Local $idMenuAbout = GUICtrlCreateMenuItem("About button", $idButtoncontext)
Local $idMenuOpen = GUICtrlCreateMenuItem("Open", $idContextmenu)
Local $idMenuSave = GUICtrlCreateMenuItem("Save", $idContextmenu)
GUICtrlCreateMenuItem("", $idContextmenu) ; separator
Local $idMenuInfo = GUICtrlCreateMenuItem("Info", $idContextmenu)
GUISetState(#SW_SHOW)
; Loop until the user exits.
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $idButton
MsgBox($MB_SYSTEMMODAL, "Button Clicked", 'OK')
Case $idMenuAbout
MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'About')
Case $idMenuOpen
MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'Open')
Case $idMenuSave
MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'Save')
Case $idMenuInfo
MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'Info')
Case $idNewsubmenuText
MsgBox($MB_SYSTEMMODAL, "SubMenu Selected", 'Text')
EndSwitch
WEnd
GUIDelete()
EndFunc ;==>Example

How to Control Firefix Dialog box with Autoit?

i try to click on OK button on firefix dialog box.
My code:
Local $hWnd=WinActivate("[CLASS:MozillaDialogClass]")
WinWaitActive($hWnd)
;MsgBox(1,$hWnd,$hWnd)
ControlClick($hWnd,"Ouverture de codeblocks_13-12_fr_430815.exe","Enregistrer le fichier")
;ControlClick($hWnd,"&Save File","")
;Close("[CLASS:MozillaDialogClass]")
When i launch, it happens nothing, the dialog box is still there but the file is not downloaded.
I got this to work with the function MouseClick after giving the window 2 seconds (sleep(2000)) to bring up the save file button.
Local $hWnd=WinActivate("[CLASS:MozillaDialogClass]"), $sWnd, $try, $coords
WinWaitActive($hWnd)
$sWnd = WinActivate("Opening code-blocks_13-12_fr_430815.exe")
WinWaitActive($sWnd)
$coords = WinGetPos($sWnd)
sleep(2000)
$try = MouseClick("", $coords[0] + 297, $coords[1] + 170, 1, 1)
If $try = 0 Then
MsgBox(0, "error", "Did not work")
EndIf

How can I remove onEvent from button widget in Corona?

I am trying to remove onEvent listener from button widget. I tried to assign nil to onEvent attribute but it didn't work and lastly I tried this:
buttonWidget : removeEventListener("touch", buttonWidget.onEvent)
I have several button like that and it just stopped all button's event listeners. What do you suggest? How can I remove the event listener for one button widget? Thanks.
Here is how I create my button widgets:
for i=0,2 do
for j=0,8 do
count=count+1
letterBtn[count] = widget.newButton{
id = alphabet[count],
left = 5+j*50,
top = H-160+i*50,
label = alphabet[count],
width = 45,
height = 45,
font = nil,
fontSize = 18,
labelColor = { default = {0,0,0}, over = {255,255,255}},
onEvent = btnOnEventHandler
};
end
end
Can you tell me how can I remove onEvent later?
Okey, I tried Button: setEnabled(false) but still it disables all buttons not just one. I already tried your second advice but it gives the same result. I am copying the rest of the code. Can you please look at it and tell me what I am missing?
local function checkLetter(e)
if(guessWord) then
for i=1, #guessWord do
local c = guessWord:sub(i,i)
if c==e.target.id then
letter[i].text = e.target.id
letterCount = letterCount +1
print("letterCount"..letterCount)
e.target:setEnabled(false)
end
end
if (letterCount == #guessWord and not hanged) then
timer.performWithDelay(500, function()
letterCount=0
rightWGuess = rightWGuess+1
for k,v in pairs(notGuessedWord) do
if v == guessWord then
notGuessedWord[k]=nil
end
end
enableButtons()
startGame() end ,1)
end
end
end
local function btnOnEventHandler(e)
if(e.phase == "began") then
checkLetter(e)
print(e.target.id)
end
return true
end
If you want to temporarily (or permanently) stop a button from responding to touch events, you can use Button:setEnabled(false).
The following worked for me for removing a listener from just 2 buttons. Button 1 and 3 stopped responding to events as expected while 2, 4, and 5 still did.
Update: To disable, you have to do it on the 'ended' phase or Corona gets confused.
widget = require 'widget'
local function btnOnEventHandler(event)
print('Event', event.target.id, event.phase)
if event.phase == 'ended' then
-- Disable the button so it can't be clicked again
-- Must disable in the end state or Corona gets
-- confused
event.target:setEnabled(false)
end
end
local buttons = {}
for i=1,5 do
buttons[i] = widget.newButton{
id = 'button' .. i,
left = display.contentCenterX - 50,
top = 60 * i,
label = 'Button ' .. i,
width = 100,
height = 50,
onEvent = btnOnEventHandler
}
end
buttons[1]:removeEventListener('touch', buttons[1].onEvent)
buttons[3]:removeEventListener('touch', buttons[3].onEvent)

Resources