From 0c97dd81be57da2644ea2c6a79711f7e3db25353 Mon Sep 17 00:00:00 2001 From: Megha Rao <52752128+megharao920@users.noreply.github.com> Date: Tue, 10 Sep 2019 09:38:20 -0400 Subject: [PATCH] Create elementHasAttribute.js Checks to see if the element has an attribute. --- mabl snippets/elementHasAttribute.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 mabl snippets/elementHasAttribute.js diff --git a/mabl snippets/elementHasAttribute.js b/mabl snippets/elementHasAttribute.js new file mode 100644 index 0000000..e199b5b --- /dev/null +++ b/mabl snippets/elementHasAttribute.js @@ -0,0 +1,27 @@ +/** + * JS snippet to get number of child elements + * @param {object} - mablInputs Object containing input + * variables (mablInputs.variables.user) + * @param {function} callback - The callback function + */ + +function mablJavaScriptStep(mablInputs, callback) { + + // Gets the page element by ID + let id_result = document.getElementById("REPLACE_WITH_ID"); + + // check that the element is not null or undefined + if (!id_result) { + throw Error('Element cannot be found'); + } + + //checks if element has attribute + let att_TF = id_result.hasAttribute("REPLACE_WITH_ATTRIBUTE"); + + if (!att_TF) { + throw Error('Attribute cannot be found'); + } + + //attribute has been found + callback(att_TF) +}