From 3434a52b8a29a875e6bc78fb7e0e14ab74f8300d Mon Sep 17 00:00:00 2001 From: lawyzheng Date: Wed, 11 Dec 2024 00:02:03 +0800 Subject: [PATCH] fix dom parsing issue --- skyvern/webeye/scraper/domUtils.js | 48 ++++++++++++++++++------------ 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/skyvern/webeye/scraper/domUtils.js b/skyvern/webeye/scraper/domUtils.js index b0c75577d..db8460212 100644 --- a/skyvern/webeye/scraper/domUtils.js +++ b/skyvern/webeye/scraper/domUtils.js @@ -787,6 +787,10 @@ const isReactSelectDropdown = (element) => { }; function hasNgAttribute(element) { + if (!element.attributes[Symbol.iterator]) { + return false; + } + for (let attr of element.attributes) { if (attr.name.startsWith("ng-")) { return true; @@ -1057,27 +1061,33 @@ function buildElementObject(frame, element, interactable, purgeable = false) { element.setAttribute("unique_id", element_id); const attrs = {}; - for (const attr of element.attributes) { - var attrValue = attr.value; - if ( - attr.name === "required" || - attr.name === "aria-required" || - attr.name === "checked" || - attr.name === "aria-checked" || - attr.name === "selected" || - attr.name === "aria-selected" || - attr.name === "readonly" || - attr.name === "aria-readonly" || - attr.name === "disabled" || - attr.name === "aria-disabled" - ) { - if (attrValue && attrValue.toLowerCase() === "false") { - attrValue = false; - } else { - attrValue = true; + if (element.attributes[Symbol.iterator]) { + for (const attr of element.attributes) { + var attrValue = attr.value; + if ( + attr.name === "required" || + attr.name === "aria-required" || + attr.name === "checked" || + attr.name === "aria-checked" || + attr.name === "selected" || + attr.name === "aria-selected" || + attr.name === "readonly" || + attr.name === "aria-readonly" || + attr.name === "disabled" || + attr.name === "aria-disabled" + ) { + if (attrValue && attrValue.toLowerCase() === "false") { + attrValue = false; + } else { + attrValue = true; + } } + attrs[attr.name] = attrValue; } - attrs[attr.name] = attrValue; + } else { + console.warn( + "element.attributes is not iterable. element_id=" + element_id, + ); } if (