// Call explorer.exe
System.Diagnostics.Process.Start("explorer.exe");
// Search for a program window with
// title "MyComputer" starting from local host
Form fileExplorer = Host.Local.FindChild<Ranorex.Form>("My Computer");
fileExplorer.Activate();
Button closeButton = fileExplorer.FindDescendant<Ranorex.Button>("Close");
closeButton.Click();
// Search for a program window
// and it's close button using the RanoreXPath
Form fileExplorer = "/form[@title='My Computer']";
fileExplorer.Activate();
Button closeButton = fileExplorer.FindSingle<Ranorex.Button>
("titlebar/button[@accessiblename='Close']");
closeButton.Click();
' Call explorer.exe
System.Diagnostics.Process.Start("explorer.exe")
' Search for a program window with
' title "MyComputer" starting from local host
Dim fileExplorer As Form = Host.Local.FindChild(Of Ranorex.Form)("My Computer")
fileExplorer.Activate()
Dim closeButton As Button = fileExplorer.FindDescendant(Of Ranorex.Button)("Close")
closeButton.Click()
' Search for a program window
' and it's close button using the RanoreXPath
Dim fileExplorer As Form = "/form[@title='My Computer']"
fileExplorer.Activate()
Dim closeButton As Button = fileExplorer.FindSingle(Of Ranorex.Button)
("titlebar/button[@accessiblename='Close']")
closeButton.Click()
# Call explorer.exe
System.Diagnostics.Process.Start("explorer.exe")
# Search for a program window with
# title "MyComputer" starting from local host
fileExplorer = Form(Host.Local.FindChild("My Computer"))
fileExplorer.Activate()
closeButton = Button(fileExplorer.FindDescendant("Close"))
closeButton.Click()
# Search for a program window
# and it's close button using the RanoreXPath
fileExplorer = Form("/form[@title='My Computer']")
fileExplorer.Activate()
closeButton = Button(fileExplorer.FindSingle("titlebar/button[@accessiblename='Close']"))
closeButton.Click()
// Search button directly with RanoreXPath
Button myButton = "/form[@title='Calculator']/button[@text='5']";
// Check if button number 5 is enabled
if (myButton.Enabled)
{
myButton.Click();
}
' Search button directly with RanoreXPath Dim myButton As Ranorex.Button = "/form[@title='Calculator']/button[@text='5']" ' Check if button number 5 is enabled If myButton.Enabled Then myButton.Click() End If
# Search button directly with RanoreXPath
myButton = Button("/form[@title='Calculator']/button[@text='5']")
# Check if button number 5 is enabled
if myButton.Enabled:
myButton.Click()
// Search textBox within .NET application
Text textBox = "/form[@controlname='TestedApp'
/text[@controlname='textBox1']";
// Set value directly
textBox.TextValue = "myText";
// Select first two characters of the
// text ("my")
textBox.Select(0, 2);
// Set values by simulating a user
// Simulate double click to select existing text
textBox.Click(Location.Center, 2);
Keyboard.Press("myText");
' Search textBox within .NET application
Dim textBox As Text = "/form[@controlname='TestedApp'/text[@controlname='textBox1']"
' Set value directly
textBox.TextValue = "myText"
' Select first two characters of the
' text ("my")
textBox.[Select](0, 2)
' Set values by simulating a user
' Simulate double click to select existing text
textBox.Click(Location.Center, 2)
Keyboard.Press("myText")
# Search textBox within .NET application
textBox = Text("/form[@controlname='TestedApp'/text[@controlname='textBox1']")
# Set value directly
textBox.TextValue = "myText"
# Select first two characters of the
# text ("my")
textBox.Select(0, 2)
# Set values by simulating a user
# Simulate double click to select existing text
textBox.Click(Location.Center, 2)
Keyboard.Press("myText")
// Search for checkbox within .NET application
CheckBox checkBox = "/form[@controlname='TestedApp']
/checkbox[@controlname='checkBox1']";
// Read the current state of a checkbox
Console.WriteLine(checkBox.Text + " State: " +checkBox.CheckState.ToString());
// Check if the checkbox is not checked
if (!checkBox.Checked)
checkBox.Checked = true;
' Search for checkbox within .NET application Dim checkBox As CheckBox = "/form[@controlname='TestedApp']/checkbox[@controlname='checkBox1']" ' Read the current state of a checkbox Console.WriteLine(checkBox.Text & " State: " & checkBox.CheckState.ToString()) ' Check if the checkbox is not checked If Not checkBox.Checked Then checkBox.Checked = True End If
# Search for checkbox within .NET application
checkBox = CheckBox("/form[@controlname='TestedApp']/checkbox[@controlname='checkBox1']")
# Read the current state of a checkbox
Console.WriteLine(checkBox.Text + " State: " + checkBox.CheckState.ToString())
# Check if the checkbox is not checked
if not checkBox.Checked:
checkBox.Checked = True
// Search for combo box within .NET application
Ranorex.ComboBox comboBox = "/form[@controlname='TestedApp']
/combobox[@controlname='comboBox1']";
// Open combobox using property
comboBox.DropDownVisible = true;
// Open combobox by clicking the
// drop down button
Button open = comboBox.FindChild<Ranorex.Button>("Open");
open.Click();
// Select list item with text "Black"
// from DropDown list
ListItem listItem = comboBox.FindSingle<ListItem>
("list/listitem[@accessiblename='Black']");
listItem.Click();
' Search for combo box within .NET application
Dim comboBox As Ranorex.ComboBox = "/form[@controlname='TestedApp']/combobox[@controlname='comboBox1']"
' Open combobox using property
comboBox.DropDownVisible = True
' Open combobox by clicking the
' drop down button
Dim open As Button = comboBox.FindChild(Of Ranorex.Button)("Open")
open.Click()
' Select list item with text "Black"
' from DropDown list
Dim listItem As ListItem = comboBox.FindSingle(Of ListItem)("list/listitem[@accessiblename='Black']")
listItem.Click()
# Search for combo box within .NET application
comboBox = ComboBox("/form[@controlname='TestedApp']/combobox[@controlname='comboBox1']")
# Open combobox using property
comboBox.DropDownVisible = True
# Open combobox by clicking the
# drop down button
open = Button(comboBox.FindChild("Open"))
open.Click()
# Select list item with text "Black"
# from DropDown list
listItem = ListItem(comboBox.FindSingle("list/listitem[@accessiblename='Black']"))
listItem.Click()
Form optionsDialog = "/form[@title='Folder Options']";
Tree settingsTree = optionsDialog.FindSingle<Ranorex.Tree>
("container[@caption='View']/tree[@controlid='30120']");
foreach (TreeItem item in settingsTree.Items)
{
IterateTree(item);
}
static void IterateTree(Ranorex.TreeItem treeItem)
{
foreach (Ranorex.TreeItem item in treeItem.Items)
{
item.Click();
CheckForWarningDialog();
Thread.Sleep(100);
if (item.Items.Count > 0)
{
IterateTree(item);
}
item.Click();
CheckForWarningDialog();
}
}
// Some mouse clicks causes a warning dialog to popup
// which has to be handled and closed
static void CheckForWarningDialog()
{
Ranorex.Button button=null;
if (Host.Local.TryFindSingle("/form[@title='Warning']/button[@text='&No']", 1000, out button))
button.Click();
}
Dim optionsDialog As Form = "/form[@title='Folder Options']"
Dim settingsTree As Tree = optionsDialog.FindSingle(Of Ranorex.Tree)("container[@caption='View']/tree[@controlid='30120']")
For Each item As TreeItem In settingsTree.Items
IterateTree(item)
Next
Private Shared Sub IterateTree(treeItem As Ranorex.TreeItem)
For Each item As Ranorex.TreeItem In treeItem.Items
item.Click()
CheckForWarningDialog()
Thread.Sleep(100)
If item.Items.Count > 0 Then
IterateTree(item)
End If
item.Click()
CheckForWarningDialog()
Next
End Sub
' Some mouse clicks causes a warning dialog to popup
' which has to be handled and closed
Private Shared Sub CheckForWarningDialog()
Dim button As Ranorex.Button = Nothing
If Host.Local.TryFindSingle("/form[@title='Warning']/button[@text='&No']", 1000, button) Then
button.Click()
End If
End Sub
optionsDialog = Form("/form[@title='Folder Options']")
settingsTree = Tree(optionsDialog.FindSingle("container[@caption='View']/tree[@controlid='30120']"))
for item in settingsTree.Items:
item = TreeItem(item)
IterateTree(item)
def IterateTree(self, treeItem):
for item in treeItem.Items:
item.Click()
self.CheckForWarningDialog()
Thread.Sleep(100)
if item.Items.Count > 0:
self.IterateTree(item)
item.Click()
self.CheckForWarningDialog()
# Some mouse clicks causes a warning dialog to popup
# which has to be handled and closed
def CheckForWarningDialog(self):
buttons = Host.Local.Find("/form[@title='Warning']/button[@text='&No']")
# if button with caption '&No' was found
# click button and close dialog
if buttons.Count > 0:
button0 = Button(buttons[0])
buttons0.Click()
The following code automates rows and cells from a Win32 table.
// Create Ranorex table using RanoreXPath from root
Table table = "/form[@title='Folder Options']/container[@caption='File Types']/table[@controlid='1000']";
table.EnsureVisible();
// Speed up mouse move
Mouse.DefaultMoveTime = 10;
bool endLoop = false;
foreach (Ranorex.Row row in table.Rows)
{
// Scrolls automatically
// when item is not visible
row.EnsureVisible();
Mouse.Click(row);
foreach (Cell cell in row.Cells)
{
Mouse.Click(cell);
// break loop if one of the
// cells contains a string 'Microsoft'
if (cell.Text.Contains("Microsoft"))
endLoop = true; ;
}
if (endLoop)
break;
}
' Create Ranorex table using RanoreXPath from root
Dim table As Table = "/form[@title='Folder Options']/container[@caption='File Types']/table[@controlid='1000']"
table.EnsureVisible()
' Speed up mouse move
Mouse.DefaultMoveTime = 10
Dim endLoop As Boolean = False
For Each row As Ranorex.Row In table.Rows
' Scrolls automatically
' when item is not visible
row.EnsureVisible()
Mouse.Click(row)
For Each cell As Cell In row.Cells
Mouse.Click(cell)
' break loop if one of the
' cells contains a string 'Microsoft'
If cell.Text.Contains("Microsoft") Then
endLoop = True
End If
Next
If endLoop Then
Exit For
End If
Next
# Create Ranorex table using RanoreXPath from root
table = Table("/form[@title='Folder Options']/container[@caption='File Types']/table[@controlid='1000']")
table.EnsureVisible()
# Speed up mouse move
Mouse.DefaultMoveTime = 10
endLoop = False
for row in table.Rows:
# Scrolls automatically
# when item is not visible
row.EnsureVisible()
Mouse.Click(row)
for cell in row.Cells:
Mouse.Click(cell)
# break loop if one of the
# cells contains a string 'Microsoft'
if cell.Text.Contains("Microsoft"):
endLoop = True
if endLoop:
break
// Create Ranorex desktop object from RanoreXPath
Desktop desktop = "/desktop";
desktop.EnsureVisible();
List desktopShortCuts = "/desktop/*/list[@controlid='1']";
Mouse.MoveTo(desktopShortCuts["Recycle Bin"]);
// Wait for tooltip
Thread.Sleep(1500);
// Read and print text of current tool tip
Console.WriteLine("Current tool tip text: " + ToolTip.Current.Text);
' Create Ranorex desktop object from RanoreXPath
Dim desktop As Desktop = "/desktop"
desktop.EnsureVisible()
Dim desktopShortCuts As List = "/desktop/*/list[@controlid='1']"
Mouse.MoveTo(desktopShortCuts("Recycle Bin"))
' Wait for tooltip
Thread.Sleep(1500)
' Read and print text of current tool tip
Console.WriteLine("Current tool tip text: " & ToolTip.Current.Text)
# Create Ranorex desktop object from RanoreXPath
desktop = Desktop("/Desktop")
desktop.EnsureVisible()
desktopShortCuts = List("/desktop/*/list[@controlid='1']")
Mouse.MoveTo(desktopShortCuts["Recycle Bin"])
# Wait for tooltip
Thread.Sleep(1500)
# Read and print text of current tool tip
Console.WriteLine("Current tool tip text: " + ToolTip.Current.Text)
// Create a Ranorex MenuBar using RanoreXPath
MenuBar menu = "/form[@controlname='TestedApp']
/menubar[@controlname='menuStrip1']";
// Get the file menu content...
// ... using index to access menu item
menu.Items[0].Click();
ContextMenu fileMenu = "/contextmenu[@processname='TestedForm']";
fileMenu.Items[0].Click(Location.CenterLeft);
// Get the file menu content...
// ... using a lable to access menu item
menu["File"].Click();
ContextMenu fileMenu = "/contextmenu[@processname='TestedForm']";
fileMenu["Item1"].Click(Location.CenterLeft);
' Create a Ranorex MenuBar using RanoreXPath
Dim menu As MenuBar = "/form[@controlname='TestedApp']/menubar[@controlname='menuStrip1']"
' Get the file menu content...
' ... using index to access menu item
menu.Items(0).Click()
Dim fileMenu As ContextMenu = "/contextmenu[@processname='TestedForm']"
fileMenu.Items(0).Click(Location.CenterLeft)
' Get the file menu content...
' ... using a lable to access menu item
menu("File").Click()
fileMenu = "/contextmenu[@processname='TestedForm']"
fileMenu("Item1").Click(Location.CenterLeft)
# Create a Ranorex MenuBar using RanoreXPath
menu = MenuBar("/form[@controlname='TestedApp']/menubar[@controlname='menuStrip1']")
# Get the file menu content...
# ... using index to access menu item
menu.Items[0].Click()
fileMenu = ContextMenu("/contextmenu[@processname='TestedForm']")
fileMenu.Items[0].Click(Location.CenterLeft)
# Get the file menu content...
# ... using a lable to access menu item
menu["File"].Click()
fileMenu = ContextMenu("/contextmenu[@processname='TestedForm']")
fileMenu["Item1"].Click(Location.CenterLeft)