Skip to content

Commit 5d53ace

Browse files
DavertMikclaude
andcommitted
fix: WebDriver strict mode - use Array.from for element collections and fix HTML unwrap regex
WebdriverIO $$ returns a special collection, not a plain array. Using Array.from() before .map() ensures WebElement[] is a real array with .length. Also fix simplifyHtmlElement regex to handle cases where <head> tag is absent in the parse5 output. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ca7ba6b commit 5d53ace

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

lib/helper/WebDriver.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3300,7 +3300,7 @@ function usingFirstElement(els) {
33003300

33013301
function assertOnlyOneElement(elements, locator, helper) {
33023302
if (elements.length > 1) {
3303-
const webElements = elements.map(el => new WebElement(el, helper))
3303+
const webElements = Array.from(elements).map(el => new WebElement(el, helper))
33043304
throw new MultipleElementsFound(locator, webElements)
33053305
}
33063306
}

lib/html.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ function splitByChunks(text, chunkSize) {
248248
function simplifyHtmlElement(html, maxLength = 300) {
249249
try {
250250
html = removeNonInteractiveElements(html)
251-
html = html.replace(/<html><head><\/head><body>(.*)<\/body><\/html>/s, '$1').trim()
251+
html = html.replace(/<html>(?:<head>.*?<\/head>)?<body>(.*)<\/body><\/html>/s, '$1').trim()
252252
} catch (e) {
253253
// keep raw html if minification fails
254254
}

0 commit comments

Comments
 (0)