AutoIt usage
The article describes some examples of using the AutoItX class when Object Recording substitutes the AutoIt driver.
Object X
Case 1
Using object X to get all window handles.
import java.lang.reflect.*;
import com.workfusion.autoit.driver.*;
import org.openqa.selenium.*;
import autoitx4java.AutoItX;
import org.apache.commons.lang3.StringUtils;
try {
Field xField = AutoItDriver.class.getDeclaredField("x");
xField.setAccessible(true);
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(modifiersField, modifiersField.getModifiers() & ~Modifier.FINAL);
AutoItX x = (AutoItX) xField.get(driver);
int numberOfAttempts = 10;
int currentAttemptNumber = 0;
while (currentAttemptNumber < numberOfAttempts) {
String hWnd = x.winGetHandle("[TITLE:App Title;CLASS:SunAwtFrame]");
if (hWnd != null && (new BigInteger(StringUtils.substringAfter(hWnd,"x"), 16)).longValue() > 0 && StringUtils.isNotBlank(hWnd)) {
int pid = AutoItHelper.intOrZero(driver.x.winGetProcess(AutoItHelper._handler(hWnd)));
if (pid > 0) {
driver.executeScript("Opt(\"WinTitleMatchMode\", 2)\n WinSetState(\"[CLASS:SunAwtFrame]\",\"\",@SW_MAXIMIZE)\n","");
Field pidsField = AutoItDriver.class.getDeclaredField("pids");
pidsField.setAccessible(true);
List<Integer> pids = (List<Integer>)pidsField.get(driver);
pids.add(pid);
pidsField.set(driver, pids);
break;
}
}
Thread.sleep(1000);
currentAttemptNumber++;
}
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
To switch to any window, add the following capability:
<capability name="SEARCH_ALL_WINDOWS" value="true" />
In that case, robot can switch to windows that were not opened by it.
Case 2
Using object X to manipulate 32-bit applications on 64-bit system.
import java.io.File;
import autoitx4java.AutoItX;
import com.jacob.com.LibraryLoader;
try {
String jacobDllVersionToUse = "jacob-1.18-M2-x86.dll";
File file = new File("lib", jacobDllVersionToUse);
System.setProperty(LibraryLoader.JACOB_DLL_PATH, file.getAbsolutePath());
AutoItX x = new AutoItX();
x.winActivate("Window 1");
x.winWaitActive("Window 1");
x.winClose("Window 1");
x.winActivate("Window 2");
x.winWaitActive("Window 2");
x.winClose("Window 2");
} catch (Exception ex){
System.out.println(ex.printStackTrace());
}
Supported automatically.
Case 3
- Using object X to manipulate 32-bit applications on 64-bit system.
- Using object X to access TreeView controls.
public static void main(String[] args) throws InterruptedException {
// Give reference to jacob dll
System.setProperty(LibraryLoader.JACOB_DLL_PATH, "C:\\RPA\\jacob\\jacob-1.18-x86.dll");
//if 64 bit java uncomment below line
// System.setProperty(LibraryLoader.JACOB_DLL_PATH, "C:\\RPA\\jacob\\jacob-1.18-x64.dll");
// System.loadLibrary("jacob-1.18-x64.dll");
String path = System.getProperty("java.library.path");
AutoItX x = new AutoItX();
String AppName_Title = "AppTitle";
String query_window="Query";
String condition_window="Condition";
x.controlFocus(AppName_Title, "", "WindowControl");
x.controlTreeViewExpand(AppName_Title, "", "WindowControl", "Queries");
x.controlTreeViewSelect(AppName_Title, "", "WindowsControl","Queries|Bot Test Query");
x.send("{APPSKEY}", false);
x.sleep(2000);
System.out.println(path);
}
Supported automatically.
Deprected AutoIt Selectors and Methods
getAttribute()
The following arguments will not be supported in the getAttribute()
method, for example, getAttribute("TabLeft").
Deprecated AutoIt commands are as follows:
| Command | Description |
|---|---|
| "IsVisible", "" | Returns 1 if Control is visible, 0 otherwise |
| "IsEnabled", "" | Returns 1 if Control is enabled, 0 otherwise |
| "ShowDropDown", "" | Displays the ComboBox dropdown |
| "HideDropDown", "" | Hides the ComboBox dropdown |
| "AddString", 'string' | Adds a string to the end in a ListBox or ComboBox |
| "DelString", occurrence | Deletes a string according to occurrence in a ListBox or ComboBox |
| "FindString", 'string' | Returns occurrence ref of the exact string in a ListBox or ComboBox |
| "SetCurrentSelection", occurrence | Sets selection to occurrence ref in a ListBox or ComboBox |
| "SelectString", 'string' | Sets selection according to string in a ListBox or ComboBox |
| "IsChecked", "" | Returns 1 if Button is checked, 0 otherwise |
| "Check", "" | Checks radio or check Button |
| "UnCheck", "" | Unchecks radio or check Button |
| "GetCurrentLine", "" | Returns the line # where the caret is in an Edit |
| "GetCurrentCol", "" | Returns the column # where the caret is in an Edit |
| "GetCurrentSelection", "" | Returns name of the currently selected item in a ListBox or ComboBox |
| "GetLineCount", "" | Returns # of lines in an Edit |
| "GetLine", line# | Returns text at line # passed of an Edit |
| "GetSelected", "" | Returns selected text of an Edit |
| "EditPaste", 'string' | Pastes the 'string' at the Edit's caret position |
| "CurrentTab", "" | Returns the current Tab shown of a SysTabControl32 |
| "TabRight", "" | Moves to the next tab to the right of a SysTabControl32 |
| "TabLeft", "" | Moves to the next tab to the left of a SysTabControl32 |
| "SendCommandID", Command ID | Simulates the WM_COMMAND message. Usually used for ToolbarWindow32 controls - use the ToolBar tab of Au3Info to get the Command ID. |
ID Selector
$('[ID:12345]')
The ID selector is not reliable and it is recommended to use other selectors.
SQL to check deprecated functionality in Business Processes
SQL query has been created to scan all bot configs and search deprecated functionality:
select
mc.content as bot_config_content,
mc.name as bot_config_name,
mc.uuid as bot_config_uuid,
c.id as step_campaign_id,
cm.parent as bp_campaign_id,
if(r.parentRunUUID is null, r.uuid, r.parentRunUUID) as bp_uuid
from Campaign c join MACHINE_CONFIG mc on c.machineConfigId=mc.id
join CampaignMap cm
join Run r
where mc.id in (select id
from MACHINE_CONFIG
where content like '%AutoItX%'
or id in(select mci.includerId
from MachineConfigInclusion mci join MACHINE_CONFIG mc on mci.includedId=mc.id
where mc.content like '%AutoItX%')
)
and c.id=cm.campaign
and r.campaign_id=cm.parent
and r.executingType='MACHINE'
group by bot_config_uuid, bp_uuid;
The query results look as follows:

bot_config_content: source code of the bot configbot_config_name: name of the bot config that contains deprecated functionalitybot_config_uuid: UUID of bot config, Control Tower bot config unique identifierstep_campaign_id: ID of campaign that has been created for BP stepbp_campaign_id: BP campaign IDbp_uuid: UUID of the BP that contains step with deprecated functionality