william_roe
9 years agoSuper Contributor
Get All Input Elements on Screen via FindChildByXPath
I've used FindChildByXPath to find first TD with click event (see below) but how do I get all controls on a page of a certain types (i.e. TextBoxes, Images, Tables, etc)?
var page = Sys.Browser().Page("*");
// finds first td with click event var obj = page.FindChildByXPath("//table[@id='grdCribPrivileges_DXMainTable']//td[text()='" + Privileges[i] + "']/parent::node()/td[@onclick]", true);
I need to write the test such that I test all input controls which are disabled and don't want to explicitly map each field and rely on devs to tell me when a new field is added.
Can anyone help help with FindChildByXPath statement below to find all Textboxes, Images, Tables, etc?
function ValidateAllControlsDisabled(){ // retrieves reference to browser var page = Sys.Browser().Page("*"); // retrieves all controls on page which should be disalbed (textbox, tables, images, etc) var allControls = page.FindChildByXPath("//Textbox", true); // NEED HELP HERE for (var i = 0; i < allControls.length; i++) { // return false if any control not disabled } }
Hi William,
Sorry for the late reply. If by "disabled" you mean any of these:
<input type="hidden" .../> <input type="text" disabled .../> <input type="text" readonly .../>
then the query for enabled inputs shoud be something like:
var arr = page.EvaluateXPath("//input[@type!='hidden' and not (@readonly or @disabled)]", true);