Skip to content

Updated snippet to remove innerText as a method, update snippet to re… #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions user snippets/getElementByXpath.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
function mablJavaScriptStep(mablInputs, callback, path = undefined) {
let element = getElementByXpath(path)
callback (element.innerText);
}
/**
* Replace this with a detailed description of what your custom JS snippet does.
* @param {object} - mablInputs Object containing input
* variables (mablInputs.variables.user)
* @param {function} callback - The callback function
* Queries the page using the supplied Xpath (path variable) and returns the first element matching the provided xpath.
* This version of the snippet is an implementation of https://github.com./mablhq/mabl-javascript-snippets/blob/main/mabl%20functions/findFirstElementMatchingXpath.js
* element.innerText can be changed to element.click() to click on the element instead of returning a value.
* @param {String} path - Xpath to find the desired element
* @returns {Element} The found element
*/
function mablJavaScriptStep(mablInputs, callback) {
/**
* Gets an element by XPath.
* @param {string} path - a valid XPath to the element
* @example
* let elementXpath = "//*[contains(text(),'match')]";
* getElementByXpath(elementXpath);
* getElementByXpath(elementXPath).click();
* getElementByXpath(elementXPath).innerText();
*/
function getElementByXpath(path) {
function findFirstElementMatchingXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
}