TestComplete recognizes standard <input>
elements of the checkbox type in web applications and on web pages as Web Check Box
objects. It can also recognize check box controls implemented with third-party libraries and frameworks.
In your tests, you can work with these elements using methods and properties of the Web Check Box
object. In addition, you can access attributes of the underlying web element and properties and methods provided to the object by a web browser in which the tested web page or web application is running.
Select or clear check box
In keyword tests
-
Add the On-Screen Action operation to your keyword test. TestComplete will show the Operation Parameters wizard.
-
In the wizard, specify the check box you want to select or clear. You can do it by pointing to the check box on the web page.
-
Select the check box object’s method to call. To simulate selecting or clearing a check box, use the
ClickChecked
method. -
To select or clear the check box, set the method’s parameter to
True
orFalse
respectively. -
Click Finish to add the operation and close the wizard.
In script tests
To simulate selecting or clearing a check box, use the WebCheckBoxObj.ClickChecked(Checked)
method.
The script sample below shows how to simulate selecting a check box on a web page:
Web (Cross-Platform)
JavaScript, JScript
{
var url = "https://services.smartbear.com/samples/TestComplete15/smartstore/login";
Browsers.Item(btChrome).Run(url);
var cb = Sys.Browser().Page(url).FindElement("#RememberMe");
// Select the Remember me check box
cb.ClickChecked(true);
}
Python
def Sample_Select_CheckBox():
url = "https://services.smartbear.com/samples/TestComplete15/smartstore/login"
Browsers.Item[btChrome].Run(url)
cb = Sys.Browser().Page(url).FindElement("#RememberMe")
# Select the Remember me check box
cb.ClickChecked(True)
VBScript
url = "https://services.smartbear.com/samples/TestComplete15/smartstore/login"
Browsers.Item(btChrome).Run(url)
Set cb = Sys.Browser().Page(url).FindElement("#RememberMe")
' Select the Remember me check box
Call cb.ClickChecked(True)
End Sub
DelphiScript
var url, cb;
begin
url := 'https://services.smartbear.com/samples/TestComplete15/smartstore/login';
Browsers.Item(btChrome).Run(url);
cb := Sys.Browser().Page(url).FindElement('#RememberMe');
// Select the Remember me check box
cb.ClickChecked(true);
end;
C++Script, C#Script
{
var url = "https://services.smartbear.com/samples/TestComplete15/smartstore/login";
Browsers["Item"](btChrome).Run(url);
var cb = Sys["Browser"]()["Page"](url)["FindElement"]("#RememberMe");
// Select the Remember me check box
cb["ClickChecked"](true);
}
Web (Classic)
JavaScript, JScript
{
var url = "https://services.smartbear.com/samples/TestComplete15/smartstore/login";
Browsers.Item(btChrome).Run(url);
var PropNames = new Array("ObjectType", "ObjectIdentifier");
var PropValues = new Array("Checkbox", "RememberMe");
var cb = Sys.Browser().Page(url).FindChildEx(PropNames, PropValues, 15, true);
// Select the Remember me check box
cb.ClickChecked(true);
}
Python
def Sample_Select_CheckBox():
url = "https://services.smartbear.com/samples/TestComplete15/smartstore/login"
Browsers.Item[btChrome].Run(url)
PropNames = ["ObjectType", "ObjectIdentifier"]
PropValues = ["Checkbox", "RememberMe"]
cb = Sys.Browser().Page(url).FindChildEx(PropNames, PropValues, 15, True);
# Select the Remember me check box
cb.ClickChecked(True)
VBScript
url = "https://services.smartbear.com/samples/TestComplete15/smartstore/login"
Browsers.Item(btChrome).Run(url)
PropNames = Array("ObjectType", "ObjectIdentifier")
PropValues = Array("Checkbox", "RememberMe")
Set cb = Sys.Browser().Page(url).FindChildEx(PropNames, PropValues, 15, True)
' Select the Remember me check box
Call cb.ClickChecked(True)
End Sub
DelphiScript
var url, PropNames, PropValues, cb;
begin
url := 'https://services.smartbear.com/samples/TestComplete15/smartstore/login';
Browsers.Item(btChrome).Run(url);
PropNames := ['ObjectType', 'ObjectIdentifier'];
PropValues := ['Checkbox', 'RememberMe'];
cb := Sys.Browser().Page(url).FindChildEx(PropNames, PropValues, 15, true);
// Select the Remember me check box
cb.ClickChecked(true);
end;
C++Script, C#Script
{
var url = "https://services.smartbear.com/samples/TestComplete15/smartstore/login";
Browsers["Item"](btChrome).Run(url);
var PropNames = new Array("ObjectType", "ObjectIdentifier");
var PropValues = new Array("Checkbox", "RememberMe");
var cb = Sys["Browser"]()["Page"](url)["FindChildEx"](PropNames, PropValues, 15, true);
// Select the Remember me check box
cb["ClickChecked"](true);
}
Get check box state
In your tests, you may need to check the state of a check box on a web page. To do this, you can use properties provided by the web browsers in which the tested web page is opened, for example, the checked
property, or the attributes of the underlying web element, for example, the value
attribute.
In keyword tests
In keyword tests, to get the check box state and perform various actions depending on the result, you can use the If … Then and Else operations:
-
Add the If … Then operation to your test.
-
Specify the condition that will get the check box state and compare it against the expected value. For example:
-
In the Value 1 column of the Operation Parameters dialog, click the ellipsis button.
-
In the resulting Edit Value dialog, set the mode to Object Property.
-
Set the value to Onscreen Object.
-
Point to the check box on the web page.
-
To get the check box state, select the
checked
property or theattributes
property, and then thevalue
attribute. Which property to use depends on the check box implementation. -
Click OK to close the dialog.
-
In the Value 2 column, enter the baseline value against which the check box state will be compared:
true
for selected andfalse
for cleared. -
Click OK to save the changes and close the Operation Parameters dialog.
-
-
To specify operations to run if the check box has the expected state, add them as child items of the If … Then operation.
-
To make the operation run otherwise, add the Else operation right after the If … Then operation, and then add the needed operations as child items of the Else operation.
In script tests
To get the state of a check box in script tests, you can use properties of the Web Check Box
object. For example, you can use the checked
property provided by a web browser or you can use the value
attribute of the underlying web element, depending on the check box implementation. The following code sample shows how you can get the state of a check box:
Web (Cross-Platform)
JavaScript, JScript
{
var url = "https://services.smartbear.com/samples/TestComplete15/smartstore/login";
Browsers.Item(btChrome).Run(url);
var cb = Sys.Browser().Page(url).FindElement("#RememberMe");
// Check if the Remember me check box is selected
if (cb.checked)
Log.Message("The Remember me check box is selected.");
else
Log.Message("The Remember me check box is cleared.");
}
Python
def Sample_CheckBox_State():
url = "https://services.smartbear.com/samples/TestComplete15/smartstore/login"
Browsers.Item[btChrome].Run(url)
cb = Sys.Browser().Page(url).FindElement("#RememberMe")
# Check if the Remember me check box is selected
if (cb.checked):
Log.Message("The Remember me check box is selected.")
else:
Log.Message("The Remember me check box is cleared.")
VBScript
url = "https://services.smartbear.com/samples/TestComplete15/smartstore/login"
Browsers.Item(btChrome).Run(url)
Set cb = Sys.Browser().Page(url).FindElement("#RememberMe")
' Check if the Remember me check box is selected
If cb.checked Then
Log.Message("The Remember me check box is selected.")
Else
Log.Message("The Remember me check box is cleared.")
End If
End Sub
DelphiScript
var url, cb;
begin
url := 'https://services.smartbear.com/samples/TestComplete15/smartstore/login';
Browsers.Item(btChrome).Run(url);
cb := Sys.Browser().Page(url).FindElement('#RememberMe');
// Check if the Remember me check box is selected
if cb.checked then
Log.Message('The Remember me check box is selected.')
else
Log.Message('The Remember me check box is cleared.');
end;
C++Script, C#Script
{
var url = "https://services.smartbear.com/samples/TestComplete15/smartstore/login";
Browsers["Item"](btChrome).Run(url);
var cb = Sys["Browser"]()["Page"](url)["FindElement"]("#RememberMe");
// Check if the Remember me check box is selected
if (cb["checked"])
Log["Message"]("The Remember me check box is selected.");
else
Log["Message"]("The Remember me check box is cleared.");
}
Web (Classic)
JavaScript, JScript
{
var url = "https://services.smartbear.com/samples/TestComplete15/smartstore/login";
Browsers.Item(btChrome).Run(url);
var PropNames = new Array("ObjectType", "ObjectIdentifier");
var PropValues = new Array("Checkbox", "RememberMe");
var cb = Sys.Browser().Page(url).FindChildEx(PropNames, PropValues, 15, true);
// Check if the Remember me check box is selected
if (cb.checked)
Log.Message("The Remember me check box is selected.");
else
Log.Message("The Remember me check box is cleared.");
}
Python
def Sample_CheckBox_State():
url = "https://services.smartbear.com/samples/TestComplete15/smartstore/login"
Browsers.Item[btChrome].Run(url)
PropNames = ["ObjectType", "ObjectIdentifier"]
PropValues = ["Checkbox", "RememberMe"]
cb = Sys.Browser().Page(url).FindChildEx(PropNames, PropValues, 15, True);
# Check if the Remember me check box is selected
if (cb.checked):
Log.Message("The Remember me check box is selected.")
else:
Log.Message("The Remember me check box is cleared.")
VBScript
url = "https://services.smartbear.com/samples/TestComplete15/smartstore/login"
Browsers.Item(btChrome).Run(url)
PropNames = Array("ObjectType", "ObjectIdentifier")
PropValues = Array("Checkbox", "RememberMe")
Set cb = Sys.Browser().Page(url).FindChildEx(PropNames, PropValues, 15, True)
' Check if the Remember me check box is selected
If cb.checked Then
Log.Message("The Remember me check box is selected.")
Else
Log.Message("The Remember me check box is cleared.")
End If
End Sub
DelphiScript
var url, PropNames, PropValues, cb;
begin
url := 'https://services.smartbear.com/samples/TestComplete15/smartstore/login';
Browsers.Item(btChrome).Run(url);
PropNames := ['ObjectType', 'ObjectIdentifier'];
PropValues := ['Checkbox', 'RememberMe'];
cb := Sys.Browser().Page(url).FindChildEx(PropNames, PropValues, 15, true);
// Check if the Remember me check box is selected
if cb.checked then
Log.Message('The Remember me check box is selected.')
else
Log.Message('The Remember me check box is cleared.');
end;
C++Script, C#Script
{
var url = "https://services.smartbear.com/samples/TestComplete15/smartstore/login";
Browsers["Item"](btChrome).Run(url);
var PropNames = new Array("ObjectType", "ObjectIdentifier");
var PropValues = new Array("Checkbox", "RememberMe");
var cb = Sys["Browser"]()["Page"](url)["FindChildEx"](PropNames, PropValues, 15, true);
// Check if the Remember me check box is selected
if (cb["checked"])
Log["Message"]("The Remember me check box is selected.");
else
Log["Message"]("The Remember me check box is cleared.");
}
See Also
Working With Application Objects and Controls
Web and RIA Testing