Can't use a title's Class to automate Windows file upload using AutoIt - automation

I am trying to use AutoIt for Windows file upload. I am clicking a browse button which will open file upload popup. I want AutoIt to type the location of the file and click open.
I need to use FF, Chrome, and IE for testing. I am able to get this to work if I use the Title, but the problem is that each browser has a different title. I would like to use class, as it is #32700 for all browsers. I've tried using class instead of the title, but its not working.
When I use title, everything works fine. Below is an example for Firefox. In this script, the file name is entered and open is clicked.
ControlFocus("File Upload","","Edit1")
ControlSetText("File Upload", "", "Edit1", "SomeFile.txt")
ControlClick("File Upload", "","Button1");
When I try to use class, text is not being entered and the open button is not getting clicked. There are no errors in the AutoIt script editor, so I'm not sure why this isn't working.
ControlFocus("[CLASS:#32770]","","Edit1")
ControlSetText("[CLASS:#32770]", "", "Edit1", "SomeFile.txt")
ControlClick("[CLASS:#32770]", "","Button1");
I've also tried to add all three browser titles to 1 AutoIt script. The below script is working for Firefox and IE, but doesn't do anything in Chrome.
Local $OrgFile = "SomeFile.csv"
Local $ControlIDText = "Edit1"
Local $ControlIDButton = "Button1"
Local $Title_FF = "File Upload"
Local $Title_Chrome = "Open"
Local $Title_IE = "Choose File to Upload"
;Firefox Import
ControlFocus($Title_FF,"",$ControlIDText)
ControlSetText($Title_FF, "", $ControlIDText, $OrgFile)
ControlClick($Title_FF, "",$ControlIDButton);
;Chrome Import
ControlFocus($Title_Chrome,"",$ControlIDText)
ControlSetText($Title_Chrome, "", $ControlIDText, $OrgFile)
ControlClick($Title_Chrome, "",$ControlIDButton);
;IE Import
ControlFocus($Title_IE,"",$ControlIDText)
ControlSetText($Title_IE, "", $ControlIDText, $OrgFile)
ControlClick($Title_IE, "",$ControlIDButton);

You need to set WinTitleMatchMode option to 4 if you want to use advanced title matching (eg. CLASS).
#RequireAdmin ;Will give your script a permission elevation (sometimes its needed)
Opt("WinTitleMatchMode", 4) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
Opt("WinSearchChildren", 1) ;0=no, 1=search children also
ControlFocus("[CLASS:#32770]","","Edit1")
ControlSetText("[CLASS:#32770]", "", "Edit1", "SomeFile.txt")
ControlClick("[CLASS:#32770]", "","Button1");

Related

How to handle a file upload button using selenium?

I am trying to access the file upload element from a webpage and handle it to upload a file and click on submit for processing. Please tell me how to handle the file upload dialog boxes? Also when using the code, it got struck-ed in the find element module itself. What can i do for that?
driver.findElement(By.id("SWFUpload_0")).click();
Robot r = new Robot();
r.keyPress(KeyEvent.VK_C); // C
r.keyRelease(KeyEvent.VK_C);
r.keyPress(KeyEvent.VK_COLON); // : (colon)
r.keyRelease(KeyEvent.VK_COLON);
r.keyPress(KeyEvent.VK_SLASH); // / (slash)
r.keyRelease(KeyEvent.VK_SLASH);
// etc. for the whole file path
r.keyPress(KeyEvent.VK_ENTER); // confirm by pressing Enter in the end
r.keyRelease(KeyEvent.VK_ENTER);

Wait for hotkey?

I'm wondering why my script doesn't wait for me to send the hotkey Alt + Shift + q?
WinWaitActive("Open")
HotKeySet("+!q", "ClickFill")
Func ClickFill()
ControlClick("Open", "", "[CLASS:32770]")
ControlSend("Open", "", "[CLASS:32770]", "C:\au3")
Exit
The script just exits after the 'Open' dialog becomes active. I'm trying to get the script to click on class 32770, which is the address bar, then send the au3 directory to it, which is my autoit scripts directory. My hope is that the script will always stay open, so any time I try to open something, it works.
Second attempt
WinWaitActive("Open")
HotKeySet("+!q", "ClickFill")
While(1)
Sleep(1000)
WEnd
Func ClickFill()
ControlClick("Open", "", "[CLASS:32770]")
ControlSend("Open", "", "[CLASS:32770]", "C:\au3")
Exit
The script remains open, but the hotkey is not effective.
It looks like you just need to close your function with a "EndFunc". This works for me.
WinWaitActive("Open")
HotKeySet("+!q", "ClickFill")
While(1)
Sleep(1000)
WEnd
Func ClickFill()
MsgBox(262144,"","Look I work!")
ControlClick("Open", "", "[CLASS:32770]")
ControlSend("Open", "", "[CLASS:32770]", "C:\au3")
Exit
EndFunc
Here is some working code for Notepad++
Global $g_hWinHandle, $g_hOpenWin
;set hotkey
HotKeySet("+!q", "ClickFill")
;open notepad++
ShellExecute(#ProgramFilesDir & "\notepad++\notepad++.exe")
;wait for notepad++ window
WinWait("[Class:Notepad++]")
If #error Then Exit
;get notepad++ window handle
$g_hWinHandle = WinGetHandle("[Class:Notepad++]")
;make sure the window is active
WinActivate($g_hWinHandle)
WinWaitActive($g_hWinHandle)
;open "Open" dialog
WinMenuSelectItem($g_hWinHandle, "", "&File", "&Open...")
;wait for "Open" dialog window
WinWaitActive("Open")
;get the "Open" dialog window handle
$g_hOpenWin = WinGetHandle("Open")
If #error Then Exit
;wait for hotkey
While (1)
Sleep(1000)
WEnd
Func ClickFill()
;make sure the window is active
WinActivate($g_hOpenWin)
WinWaitActive($g_hOpenWin)
;focus the toolbar
ControlFocus($g_hOpenWin, "", "[CLASS:ToolbarWindow32; INSTANCE:3]")
ControlCommand($g_hOpenWin, "", "[CLASS:ToolbarWindow32; INSTANCE:3]", "SendCommandID", "1280")
;send our command to the toolbar
ControlSetText($g_hOpenWin, "", "Edit2", "C:\au3")
ControlSend($g_hOpenWin, "", "Edit2", "{ENTER}")
Exit
EndFunc ;==>ClickFill
In the above example you will see that I use ControlFocus and ControlCommand on the ToolbarWindow32 control. Most dialog windows have a ToolbarWindow32 control. To simulate clicking on them you have to use ControlCommand with the SendCommandID option. You can get that ID under the toolbar tab in the AutoIt info tool. However, you will see that once the ToolbarWindow32 control is clicked on it gives focus to an edit control. That edit control is what you need to send text to if you want to change directories. Finding that edit control with the AutoIt tool can be a bit tricky. You will have to make sure "Freeze" is unchecked under options.
If you are still having problems with the code I would recommend that you first make sure you can get the code working without a hotkey. Then try it with a one letter hotkey and then lastly try it with your multiple hotkey combination. With out having access to your computer I am just guessing but I suspect that you are not accessing the address bar right. There might also be a program running on your computer that is using the same hotkey.

Three AutoIT script causing issue

All,
I have Selenium script which attach documents to Transaction. I am using AutoIT. Now, the problem I am facing is: I have to attach 3 documents (one by one). My steps are: I execute AutoIT script. Then script click on Browse 1 - button in my transaction screen - File Upload pop up appears. My Address of file is pasted correctly in text area as well.
But when AutoIT script click on Open button - another File Upload window appears.
I did added some wait in my script before clicking on Browser 2 button. But somehow I am missing something which is causing this problem.
Another thing is that: Same script works sometimes. Failure is more than success.
WinExists ("TITLE")
While 1
Select
case WinExists("File Upload")
WinActivate("File Upload")
Sleep(5000)
Local $sTestPath = _PathFull(#ScriptDir & "\ABC.jpg")
ControlClick("File Upload", "", "Edit")
Send($sTestPath)
Sleep(5000)
Send("{ENTER}")
Sleep(5000)
Exit
Case WinExists("Choose File to Upload")
WinActivate("Choose File to Upload")
Sleep(5000)
Local $sTestPath = _PathFull(#ScriptDir & "\ABC.jpg")
ControlClick("File Upload", "", "Edit")
Send($sTestPath)
Sleep(5000)
Send("{ENTER}")
Sleep(5000)
Exit
Case WinExists("Open")
WinActivate("Choose File to Upload")
Sleep(5000)
Local $sTestPath = _PathFull(#ScriptDir & "\ABC.jpg")
ControlClick("File Upload", "", "Edit")
Send($sTestPath)
Sleep(5000)
Send("{ENTER}")
Sleep(5000)
Exit
EndSelect
WEnd
Don't use send.
Send ( "keys" [, flag] ) - Sends simulated keystrokes to the active
window.
Better way:
ControlSend () can send characters to targeted window (can be inactive).
Most reliable way:
ControlSetText () - Sets text of a control.
Play with AutoitWindowInfo tool and tweak the script below if needed.
#RequireAdmin ;Will give your script a permission elevation (sometimes its needed)
Opt("WinTitleMatchMode", 1) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
Opt("WinSearchChildren", 1) ;0=no, 1=search children also
WinActivate("File Upload")
WinWaitActive("File Upload","",10)
ControlFocus("File Upload","","Edit1")
ControlSetText("File Upload","","Edit1","dropdowns.jpg")
ControlSend("File Upload", "", "Edit1", "{ENTER}")

Autoit and notepad

I have an application, wherein I get a "Save As" dialog-box. At times, if a file exists with the same name, then another dialog box comes in, with the same name "Save As". The following is the code, which I wrote but it doesn't work as expected.
Global $sTitle = "Save As"
WinWait($sTitle)
WinWaitActive($sTitle)
ControlClick($sTitle, "Save", "[CLASS:Button; TEXT:&Save; INSTANCE:2]")
ControlSetText($sTitle, "", "CLASS:Button; INSTANCE:2]", $file_name)
SendKeepActive($sTitle)
Send("{ENTER}")
Sleep(4000)
WinWaitActive($sTitle,"",3)
If WinExists($sTitle, "No") Then Send("{ENTER}")
If WinExists("Exit OmniPeek") Then
Send("{ENTER}")
Else
Sleep(2000)
WinClose($closing_file)
EndIf
The idea is to check if the second "Save As" dialog box comes and if does come in, then over-write the existing file. This however, doesn't seem to be working with the autoit script that I wrote.
Can someone help me with this script? You can re-create the issue by using Notepad as well. Just have a file with a name abc.txt and try to save a file with the same name
You will get another dialog box with the name "Save As".
Try this:
Example()
Func Example()
; Run Notepad
Run("notepad.exe")
; Wait 10 seconds for the Notepad window to appear.
Local $hWnd = WinWait("[CLASS:Notepad]", "", 10)
; Keep the Notepad window active when using the Send function.
SendKeepActive("[CLASS:Notepad]")
; Simulate entering a string of text. If you try to change to a different window other than Notepad, then the Notepad window will
; be brought to focus again.
For $i = 1 To 10
Sleep(5)
Send("notepad - ")
Next
; Disable the Notepad window being active when using the Send function.
SendKeepActive("")
; Close the Notepad window using the handle returned by WinWait.
WinClose($hWnd)
Send("{ENTER}") ; <<< SAVE
; Now a screen will pop up and ask to save the changes, the classname of the window is called
; "#32770" and simulating the "TAB" key to move to the second button in which the "ENTER" is simulated to not "save the file"
WinWaitActive("[CLASS:#32770]", '', 2)
Sleep(50)
Send('newName.txt')
Sleep(1000)
Send("{TAB}{ENTER}")
EndFunc ;==>Example

application Support folder doesn't have iphone folder while creating a directory

I am creating a directory using Phonegap. I am getting success while using code. But I need to check where my folder is created. I found link they told these link.
/Users/UserName/Library/Application Support/iPhone Simulator/4.3.2/Applications
/Users/loginname/Library/Application Support/iPhone Simulator/6.1/Applications/YOUR_APP/Documents
But I don't have any iPhone simulator folder in application support? Where I will search?
I have Xcode 4.5 version
How to find android directory using the same code .i am able to in Ios
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, onFileSystemFail);
}
function onFileSystemSuccess(fileSystem) {
console.log(fileSystem.name);
var directoryEntry = fileSystem.root;
directoryEntry.getDirectory("newDir", {create: true, exclusive: false}, onDirectorySuccess, onDirectoryFail)
}
function onDirectorySuccess(parent) {
//alert("onSuccess")
console.log(parent);
// alert(parent+"Directory");
}
function onDirectoryFail(error) {
alert("Unable to create new directory: " + error.code);
}
function onFileSystemFail(evt) {
console.log(evt.target.error.code);
alert(evt.target.error.code);
}
The simplest solution is just copy the url
Go to the finder and press command + shift + G and paste your url and press Go
You don't need to enable hidden file.
make sure you're not searching for it because you will get the wrong application folder, you have to go to your "user name" folder and make it show hidden files and that will show the hidden library file so you can start navigating your way to that address... try that and anymore issues with it ill try and help further.
if you dont know how to open terminal go to search magnifying glass top right corner, click it and in the finder search bar type in terminal and press enter. a terminal window will pop up and after you copy this line " defaults write com.apple.Finder AppleShowAllFiles TRUE " copy that without the " " part. now right click "if you have a two buttton mouse " on that terminal window and click paste from the menu that pops up, now press enter. now last thing is to close all finder windows so copy this " killall Finder " without quotes and paste that in terminal and press enter...now your hidden folders will come up in your finder windows and the new faded hidden librarry folder will be under mac/users/"whatever ur username is "/