Jump to content

MakzNovice

Active Members
  • Posts

    41
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

MakzNovice's Achievements

Seeker

Seeker (1/7)

0

Reputation

  1. @SOLVE-SMART Yes it indeed fit my requirement, quick and effective fix for long term problem. I had to change my program to meet my needs as you mentioned. I made it slightly more robust by skipping pixel search and instead using approach of source and target Top-Left corner coordinates (WinGetPos) + relative target location to finalize my X and Y. Also confirmed that Firefox window will be 100% zoom. so chances of error are reduced. My code for reference #include <MsgBoxConstants.au3> Opt('MouseCoordMode', 0) Opt('MustDeclareVars', 1) Opt('WinTitleMatchMode', 2) ; declaration ------------------------------------------------------------------ Global $sTitle = 'FileUploadDemo' Global $sTargetFolderOfFiles = @TempDir & '\' & $sTitle & '\' Global $iFolderWindowWidth = 200 Global $iFolderWindowHeight = 200 Global $iFileExplorerFile1X = 61 Global $iFileExplorerFile1Y = 114 Global $iFileExplorerFile2X = 61 Global $iFileExplorerFile2Y = 134 ;~ Cordinates for Global $iTargetXPosition1 = 75 Global $iTargetYPosition1 = 274 Global $iTargetXPosition2 = 175 Global $iTargetYPosition2 = 274 Global $sTitleString = "Mozilla Firefox" Global $hWndExplorer, $hWndFF ; processing ------------------------------------------------------------------- DirCreate($sTargetFolderOfFiles) _writeFile($sTargetFolderOfFiles & 'file1.txt', 'upload file 1') _writeFile($sTargetFolderOfFiles & 'file2.txt', 'upload file 2') _openFolder($sTargetFolderOfFiles) _setExplorerFolderWindowPosition() _setFireFoxWindowActive() _selectFirstFileInOpenedFolder() _dragAndDropByPixelColor() ;~ WinClose($hWndExplorer) ; Explorer window will be closed after work is done ; functions -------------------------------------------------------------------- Func _writeFile($sFile, $sText) Local Const $iUtf8WithoutBomAndOverwriteCreationMode = 256 + 2 + 8 Local $hFile = FileOpen($sFile, $iUtf8WithoutBomAndOverwriteCreationMode) FileWrite($hFile, $sText) FileClose($hFile) EndFunc Func _openFolder($sFolderPath = @DesktopDir) ShellExecute($sFolderPath) EndFunc Func _setFireFoxWindowActive() If ProcessExists("Firefox.exe") Then $hWndFF = WinGetHandle($sTitleString) WinActivate($hWndFF) Else MsgBox(64,"Error","No Firefox window found, closing script") Exit EndIf EndFunc Func _setExplorerFolderWindowPosition() $hWndExplorer = WinGetHandle($sTitle) WinActivate($sTitle) WinWaitActive($sTitle, '', 2) WinMove($sTitle, '', 0, 0, $iFolderWindowWidth, $iFolderWindowHeight) EndFunc Func _selectFirstFileInOpenedFolder() WinActivate($hWndExplorer) Send('{DOWN}') Sleep(100) Send('{UP}') EndFunc Func _dragAndDropByPixelColor() Sleep(1000) ;~ PixelSearch is not suitable for my need, lets use WinGetPos ;Local $aCoordinates1 = PixelSearch($iSearchRectangleLeft, $iSearchRectangleTop, $iSearchRectangleRight, $iSearchRectangleBottom, $vSearchColor) ;MsgBox(64, "", "X and Y are: " & $aCoordinates[0] & "," & $aCoordinates[1]) ;Local $iOffset = 5 WinActivate($hWndExplorer) Local $aPosExplorer = WinGetPos($hWndExplorer) ;Display the array values returned by WinGetPos. MsgBox($MB_SYSTEMMODAL, "Explorer details", "X-Pos: " & $aPosExplorer[0] & @CRLF & _ "Y-Pos: " & $aPosExplorer[1] & @CRLF & _ "Width: " & $aPosExplorer[2] & @CRLF & _ "Height: " & $aPosExplorer[3]& @CRLF, 1) $iFileExplorerFile1X = $aPosExplorer[0] + $iFileExplorerFile1X $iFileExplorerFile1Y = $aPosExplorer[1] + $iFileExplorerFile1Y Sleep(1000) WinActivate($hWndFF) Local $aPos = WinGetPos($hWndFF) ; Display the array values returned by WinGetPos. MsgBox($MB_SYSTEMMODAL, "FireFox Window details", "X-Pos: " & $aPos[0] & @CRLF & _ "Y-Pos: " & $aPos[1] & @CRLF & _ "Width: " & $aPos[2] & @CRLF & _ "Height: " & $aPos[3]& @CRLF, 1) $iTargetXPosition1 = $aPos[0] + $iTargetXPosition1 $iTargetYPosition1 = $aPos[1] + $iTargetYPosition1 WinActivate($hWndExplorer) _mouseDragAndDrop($iFileExplorerFile1X, $iFileExplorerFile1Y, $iTargetXPosition1, $iTargetYPosition1) EndFunc Func _mouseDragAndDrop($iFromX, $iFromY, $iToX, $iToY, $iSpeed = 30) ;~ MouseClickDrag() isn't working, that's why I add this function Local $sMouseKey = 'primary' MouseMove($iFromX, $iFromY, $iSpeed) MouseDown($sMouseKey) MouseMove($iToX, $iToY, $iSpeed) MouseUp($sMouseKey) EndFunc I will keep hunting for better solution including webdriver approach, but this is good workaround for me. Any further support will be appreciated.
  2. @mLipok I wish we could use IE.. But as you know due to various issue the only browser allowed is Firefox.
  3. @mLipok Sorry I just confirmed one thing, I do not have option retrieve/ask for user credentials.. I am automating very small process of bigger tool, which has user already logged in and then this a part of internal operation. - But seems webdriver approach is not going to work since we can't get existing page details.. Sorry again for my poor English which did not clarify that user credentials can't be requested.
  4. @mLipok It will work on my machine with my credentials, but would be problematic if other users use the script. Also, I tried next steps manually and it takes almost 8-9 more steps to reach the page I need too... Needless to say the page is dynamic, clicks are to be decided by other user actions... So its tough to automate logically till this page.
  5. @SOLVE-SMART That is what I tried in my first script, mouse clicks, but it won't work on firefox webpage Really need to find a way as good as this _WD_SelectFiles.. if somehow can just crack a way to get handle of existing webpage...
  6. Well if that is the case it seems , approach of Webdriver is going to be less useful for my case. Because the first page is login credentials and which in my case I may not have, if others launches the executable. Looking forward from response/confirmation from @mLipok or @Danp2 Is there any other way to achieve my requirement to upload files to existing webpage in firefox?
  7. @mLipok So is there a way to get handle of existing page or no option to get it?
  8. @mLipok I am trying the webdriver UDF as given in sample for firefox, I am stuck at very basic step though.. 1. I have my firefox session page already launched, how can I gets associate it Session created by _WD_CreateSession? _WD_Navigate - opens new page, if I pass second argument as URL, which requires login and everything else( not what I desire) I tried $hWnd = WinGetHandle($sTitleString) and then _WD_Navigate($sSession,$hWnd) but it fails too.. _WD_Attach - looks for page by title created in session and fails My aim is to read the page that I already have, but all the _WD_* operations seem to need session id created using _WD_CreateSession. I want to know how can I read existing firefox webpage and be able to call methods like _WD_SelectFiles or _WD_FindElements Any snippet would be of great help here 2. In _WD_SelectFiles($sSession, $sStrategy, $sSelector, $sFilename) , what types of drop are supported As per documentation of method - $sSelector - Value to find. Should point to element of type '< input type="file" >' The information that I have about by drop location by developer tools is - <div id='divFiledrop' class='dropArea'.... does the class gets supported by this method ? Any response will be highly appreciated
  9. I have a simple code that takes file "C:\Temp\File1.txt" and pastes it in drop area of specific firefox location ( Note : The drag drop works manually meaning firefox window supports drag and drop) . The return value is true with no error indicating that operation successful. The results are not getting updated in firefox window even after exe execution completion and sleep time 20secs. Attached my code snippet and _FileDragDrop.au3 + text file it works #include "_FileDragDrop.au3" Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase Opt("MouseCoordMode", 0) ;1=absolute, 0=relative, 2=client $File1 = "E:\AutoIt\DragDropFile\File1.txt" $File2 = "E:\AutoIt\DragDropFile\File2.txt" If ProcessExists("Firefox.exe") Then $hWnd = WinGetHandle("Mozilla Firefox") ; My FF tab title substring WinActivate($hWnd) Else MsgBox(64,"Error","No Firefox window found",10) EndIf $hNPPlus=WinGetHandle("[CLASS:Notepad++]") WinActivate($hNPPlus) $iRet = _FileDragDrop($hNPPlus, $File1, 75, 274) ConsoleWrite("Return: "&$iRet&" @error="&@error&", @extended="&@extended&@CRLF) Sleep(20000) ;~ Above code to add in Notepad++ works fine ;~ Cordinate from drop file 1 - 75, 274 $iRet = _FileDragDrop($hWnd, $File1, 75, 274,'|',False) ConsoleWrite("Return: "&$iRet&" @error="&@error&", @extended="&@extended&@CRLF) Sleep(20000) ;~ Above code to add file in firefox with title Mozilla firefox DOES NOT work Exit Repose from code --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop Return: True @error=0, @extended=0 Return: True @error=0, @extended=0 _FileDragDrop.au3 File1.txt
  10. @junkew any sharable information? Any other expert who can help me out here?
  11. @junkew : I had to take break from this script for some time Can I ask have you tried using ControlSend or ControlClick instead of Send and MouseClick in your _UIA_action methods? I tried doing so but it does nothing , even uncommented your logs using UIA_log . its just says object is non-existent. Attached is your xml log file .. last two lines show the are from UIA_Action method. I have tried below two options but same result. 1. Used $oElement _UIA_LOG("Title is: <" & _UIA_getPropertyValue($UIA_oUIElement,$UIA_NamePropertyId) & ">" & $clickcount & ":" & $clickaction & ":" & $x & ":" & $y & ":" & @CRLF, $UIA_Log_Wrapper) ;~ TODO: Check if setting focus should happen as it influences behavior before clicking ;~ Tricky when using setfocus on menuitems, seems to do the click already ;~ $obj.setfocus() ;~ Mouse should move to keep it as userlike as possible ;MouseMove($x, $y, 0) ;~ mouseclick($clickAction,Default,Default,$clickCount,0) If Not StringInStr($strAction, "move") Then ;MouseClick($clickAction, $x, $y, $clickCount, 0) ControlClick($oElement,"","",$clickAction,$clickcount,$x,$y) ControlSend($oElement,"","","{ENTER}") $error = @error _UIA_LOG("Error is: <" & $error & @CRLF, $UIA_Log_Wrapper) EndIf Sleep($UIA_DefaultWaitTime) and 2. Used input $obj2ActOn _UIA_LOG("Title is: <" & _UIA_getPropertyValue($UIA_oUIElement,$UIA_NamePropertyId) & ">" & $clickcount & ":" & $clickaction & ":" & $x & ":" & $y & ":" & @CRLF, $UIA_Log_Wrapper) ;~ TODO: Check if setting focus should happen as it influences behavior before clicking ;~ Tricky when using setfocus on menuitems, seems to do the click already ;~ $obj.setfocus() ;~ Mouse should move to keep it as userlike as possible ;MouseMove($x, $y, 0) ;~ mouseclick($clickAction,Default,Default,$clickCount,0) If Not StringInStr($strAction, "move") Then ;MouseClick($clickAction, $x, $y, $clickCount, 0) ControlClick($obj2ActOn,"","",$clickAction,$clickcount,$x,$y) ControlSend($obj2ActOn,"","","{ENTER}") $error = @error _UIA_LOG("Error is: <" & $error & @CRLF, $UIA_Log_Wrapper) EndIf Sleep($UIA_DefaultWaitTime) Note: The passed object to method is $obj2ActOn that I get from _UIA_getObjectByFindAll method call done, which is retrieved successfully as you can see in log file 20200914-072602771.XML
  12. @BigDaddyO Thank you for your answer, I apologize for late response was occupied with some personal work. But as I mentioned earlier problem is not with keeping session alive, it about running Adobe on 'minimized remote machine' such way that Adobe is launched in foreground. The code you gave only keeps my session alive, now as I mentioned I use @junkew developed UIA automation API to identify objects/controls and perform action on them. The method in UIA Automation ( _UIA_Action ) script internally calls 'Send' which I guess is problem ( May be @junkew can confirm..) Also, I use a lot of WinActive, WinActivate, WinWait in my script, so it also is problem, I am re-pasting the code if you guys ( @BrewManNH, @junkew ) can help me suggest alternatives. #include <FileConstants.au3> #include <StringConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <constants.au3> #include <constants.au3> #include <WinAPI.au3> #include <debug.au3> #include "CUIAutomation2.au3" #include "UIAWrappers.au3" #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> ; used for chcking is the script is Singleton #include <Misc.au3> #include <ColorConstantS.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> Global $ACROBAT_DC_EXE_PATH = "C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Acrobat.exe" Global $PdfFileName = "AppDevGuide.pdf" MyFunction Func MyFunction() Local $Run = $ACROBAT_DC_EXE_PATH & " " & @ScriptDir & "\" & $PdfFileName ConsoleWrite("$Run : " & $Run & @CRLF) Local $PID = Run($Run, "", @SW_MAXIMIZE) ConsoleWrite("$PID : " & $PID & @CRLF) Local $list = WinList() For $i = 1 To $list[0][0] If WinGetProcess($list[$i][0]) = $PID And $list[$i][0] Then ;we need activate only window that matches our PID and has a title ConsoleWrite("Found $PID : " & $PID & @CRLF) WinSetState($list[$i][1], "", @SW_SHOW) WinActivate($list[$i][1]) ExitLoop EndIf Next Local $szDrive, $szDir, $szFName, $szExt _PathSplit($fileName, $szDrive, $szDir, $szFName, $szExt) ConsoleWrite("$szDrive : " & $szDrive & @CRLF) ConsoleWrite("$szDir : " & $szDir & @CRLF) ConsoleWrite("$szFName : " & $szFName & @CRLF) ConsoleWrite("$szExt : " & $szExt & @CRLF) ;~ Make the PDF file as active and on top WinWait($szFName) WinActivate($szFName) ConsoleWrite("Activated : " & $szFName & @CRLF) _FileWriteLog($LOG_FILE_PATH, "Activated : " & $szFName) ;~ Wait for all the contents to be loaded Sleep(5000) ConsoleWrite("Sleep(5000)" & @CRLF) ConsoleWrite("Trying to get Find tools command" & @CRLF) Local $oP5 = _UIA_getObjectByFindAll($UIA_oDesktop, "Title:=;controltype:=UIA_WindowControlTypeId;class:=AcrobatSDIWindow", $treescope_children) _UIA_Action($oP5, "setfocus") Local $oP4 = _UIA_getObjectByFindAll($oP5, "Title:=;controltype:=UIA_GroupControlTypeId;class:=AVL_AVView", $treescope_children) _UIA_Action($oP4, "setfocus") Local $oP3 = _UIA_getObjectByFindAll($oP4, "Title:=;controltype:=UIA_PaneControlTypeId;class:=AVL_AVView", $treescope_children) _UIA_Action($oP3, "setfocus") Local $oP2 = _UIA_getObjectByFindAll($oP3, "Title:=Right Hand Tools Pane;controltype:=UIA_PaneControlTypeId;class:=AVL_AVView", $treescope_children) _UIA_Action($oP2, "setfocus") Local $oP1 = _UIA_getObjectByFindAll($oP2, "Title:=;controltype:=UIA_GroupControlTypeId;class:=", $treescope_children) Local $oP0 = _UIA_getObjectByFindAll($oP1, "Title:=;controltype:=UIA_GroupControlTypeId;class:=", $treescope_children) ;~ First find the object in the parent before you can do something Local $oUIElement = _UIA_getObjectByFindAll($oP0, "title:=Find Tools;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree) _UIA_action($oUIElement, "click") ConsoleWrite("I clicked Find tool " & @CRLF) ;~ Add the Send For Shared Commenting text in editor Send("Send For Review") ConsoleWrite("I Entered text in search Send For Review" & @CRLF) ; MOST important wait for some time after sending $COMMAND_STRING Sleep(5000) ConsoleWrite("Sleep(5000)" & @CRLF) $oP5 = _UIA_getObjectByFindAll($UIA_oDesktop, "Title:=;controltype:=UIA_WindowControlTypeId;class:=AcrobatSDIWindow", $treescope_children) _UIA_Action($oP5, "setfocus") $oP4 = _UIA_getObjectByFindAll($oP5, "Title:=;controltype:=UIA_GroupControlTypeId;class:=AVL_AVView", $treescope_children) _UIA_Action($oP4, "setfocus") $oP3 = _UIA_getObjectByFindAll($oP4, "Title:=;controltype:=UIA_PaneControlTypeId;class:=AVL_AVView", $treescope_children) _UIA_Action($oP3, "setfocus") $oP2 = _UIA_getObjectByFindAll($oP3, "Title:=Right Hand Tools Pane;controltype:=UIA_PaneControlTypeId;class:=AVL_AVView", $treescope_children) _UIA_Action($oP2, "setfocus") $oP1 = _UIA_getObjectByFindAll($oP2, "Title:=;controltype:=UIA_GroupControlTypeId;class:=AVL_AVView", $treescope_children) _UIA_Action($oP1, "setfocus") $oP0 = _UIA_getObjectByFindAll($oP1, "Title:=;controltype:=UIA_PaneControlTypeId;class:=AVL_AVView", $treescope_children) _UIA_Action($oP0, "setfocus") _UIA_setVar(".mainwindow", "title:=;classname:=AVL_AVView") _UIA_action(".mainwindow", "setfocus") ConsoleWrite("Highliting the Send For Review command" & @CRLF) ; Send ;Send("{TAB 1}") ;Send("{ENTER}") Local $oP8 = _UIA_getObjectByFindAll($UIA_oDesktop, "Title:=;controltype:=UIA_WindowControlTypeId;class:=AcrobatSDIWindow", $treescope_children) _UIA_Action($oP8, "setfocus") Local $oP7 = _UIA_getObjectByFindAll($oP8, "Title:=;controltype:=UIA_GroupControlTypeId;class:=AVL_AVView", $treescope_children) _UIA_Action($oP7, "setfocus") Local $oP6 = _UIA_getObjectByFindAll($oP7, "Title:=;controltype:=UIA_PaneControlTypeId;class:=AVL_AVView", $treescope_children) _UIA_Action($oP6, "setfocus") $oP5 = _UIA_getObjectByFindAll($oP6, "Title:=Right Hand Tools Pane;controltype:=UIA_PaneControlTypeId;class:=AVL_AVView", $treescope_children) _UIA_Action($oP5, "setfocus") $oP4 = _UIA_getObjectByFindAll($oP5, "Title:=;controltype:=UIA_GroupControlTypeId;class:=AVL_AVView", $treescope_children) _UIA_Action($oP4, "setfocus") $oP3 = _UIA_getObjectByFindAll($oP4, "Title:=;controltype:=UIA_PaneControlTypeId;class:=AVL_AVView", $treescope_children) _UIA_Action($oP3, "setfocus") $oP2 = _UIA_getObjectByFindAll($oP3, "Title:=;controltype:=UIA_PaneControlTypeId;class:=AVL_AVView", $treescope_children) _UIA_Action($oP2, "setfocus") $oP1 = _UIA_getObjectByFindAll($oP2, "Title:=;controltype:=UIA_GroupControlTypeId;class:=AVL_AVView", $treescope_children) _UIA_Action($oP1, "setfocus") $oP0 = _UIA_getObjectByFindAll($oP1, "Title:=;controltype:=UIA_GroupControlTypeId;class:=", $treescope_children) ;~ First find the object in the parent before you can do something $oUIElement = _UIA_getObjectByFindAll($oP0, "title:=Send for Shared Commenting;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree) _UIA_action($oUIElement, "click") ConsoleWrite("Must have clicked Send for Review " & @CRLF) Sleep(500) WinActivate($szFName) ;~ Close the opened file Send("!f") Send("c") Sleep(2000) ConsoleWrite("Alt + F then C to close file.... " & @CRLF) _FileWriteLog($LOG_FILE_PATH, "Alt + F + C to close file.... " ) _FileWriteLog($LOG_FILE_PATH, "Sleep(2000)") ;~ Close the Acrobat Application Send("!f") Send("x") Sleep(3000) ConsoleWrite("Alt + F then X to Exit Acrobat .... " & @CRLF) _FileWriteLog($LOG_FILE_PATH, "Alt + F then X to Exit Acrobat .... " ) _FileWriteLog($LOG_FILE_PATH, "Sleep(3000)") ;~ Now close the pdf application forcefully if it still exists If ProcessExists($PID) Then ProcessClose($PID) ConsoleWrite("Acrobat found, Killing it.... " & @CRLF) _FileWriteLog($LOG_FILE_PATH, "Acrobat found, Killing it.... " ) EndIf EndFunc
  13. @seadoggie01 The problem is it needs user id and password as mandatory fields, which is where my problem lies.
  14. Experts, I am using _INetsmtpMail method and it works wonderfully for me. But the problem is, I am not sure how can I have some hyperlink or font variation/color variation in email body. Example : in below code I would like to have fifth line as hyperlink to some page ( say www.google.com) and sixth (last) line as smaller font with red color ( like warning) #include <Inet.au3> #include <MsgBoxConstants.au3> Local $s_SmtpServer = "mysmtpserver.com.au" Local $s_FromName = "My Name" Local $s_FromAddress = "From eMail Address" Local $s_ToAddress = "To eMail Address" Local $s_Subject = "My Test UDF" Local $as_Body[6] $as_Body[0] = "Hello MakzNovice," $as_Body[1] = "" $as_Body[2] = "Can you do this for me?" $as_Body[3] = "" $as_Body[4] = "Some Hyperlink 'here'" $as_Body[5] = "small font with Red color text here" Local $iResponse = _INetSmtpMail($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body) Local $iErr = @error If $iResponse = 1 Then MsgBox($MB_SYSTEMMODAL, "Success!", "Mail sent") Else MsgBox($MB_SYSTEMMODAL, "Error!", "Mail failed with error code " & $iErr) EndIf Any guidelines or help will be highly appreciated. Cheers !!!
×
×
  • Create New...