Skip to content

[javascript] Migrate find-elements atom from Closure to TypeScript#17458

Merged
AutomatedTester merged 2 commits into
trunkfrom
cool-kalam-ecbae2
May 14, 2026
Merged

[javascript] Migrate find-elements atom from Closure to TypeScript#17458
AutomatedTester merged 2 commits into
trunkfrom
cool-kalam-ecbae2

Conversation

@AutomatedTester
Copy link
Copy Markdown
Member

Summary

  • Replaces the Google Closure bot.locators.findElements fragment (//javascript/atoms/fragments:find-elements.js) with a self-contained TypeScript IIFE, following the same pattern as get-attribute and is-displayed
  • Updates py/BUILD.bazel to consume the new TypeScript-generated file instead of the Closure output
  • Adds a QUnit browser test covering all locator strategies

What changed

New files:

  • javascript/atoms/typescript/find-elements.ts — TypeScript IIFE that implements all locator strategies without any Closure or external dependencies: css selector, id, class name, tag name, link text, partial link text, name, xpath, and the full relative locator (above/below/left/right/near and straight-* variants with proximity sort matching the Closure original)
  • javascript/atoms/typescript/wrap-find-elements-as-global.js — Node script that wraps compiled output as window.bot.locators.typescript.findElements for browser test pages
  • javascript/atoms/test/find_elements_typescript_test.html — 18 QUnit tests exercising each strategy in a real browser via the existing closure_test_suite infrastructure

Updated files:

  • javascript/atoms/BUILD.bazel — tsc compile, strip-semicolon, global-wrap targets; find-elements-global added to the atoms filegroup
  • javascript/atoms/fragments/BUILD.bazelcopy_file target find-elements-typescript with same visibility as the old Closure fragment
  • py/BUILD.bazelfind-elements copy_file src switched from find-elements.js to find-elements-typescript.js

Testing

  • //py:test/selenium/webdriver/support/relative_by_tests-chrome-bidiPASSED (this is the primary consumer of findElements in Python; it exercises all relative locator directions including near, above, below, left, right, straight-* variants)
  • TypeScript compilation succeeds via bazel build //javascript/atoms:find-elements-typescript-generated
  • Two unrelated pre-existing failures in window_tests and api_example_tests are window-position assertions that fail on multi-monitor macOS setups; they are not affected by this change

Notes for reviewers

The findElements atom is used by Python (and Java/Ruby/dotnet — unchanged here) exclusively for RelativeBy locators. The calling convention from Python is:

find_element_js = f"/* findElements */return ({raw_function}).apply(null, arguments); "
self.execute_script(find_element_js, by.to_dict())
# by.to_dict() → {"relative": {"root": {...}, "filters": [{"kind": "above", "args": [element]}]}}

WebElement references in args are deserialized to actual DOM Element objects by the browser before the script runs, matching the behaviour expected by the resolveAnchor function.

Replace the Google Closure `bot.locators.findElements` fragment with a
self-contained TypeScript implementation, following the same pattern
used for `get-attribute` and `is-displayed`.

New files:
- javascript/atoms/typescript/find-elements.ts — IIFE implementing all
  locator strategies: css selector, id, class name, tag name, link text,
  partial link text, name, xpath, and the full relative locator
  (above/below/left/right/near and straight-* variants with proximity sort)
- javascript/atoms/typescript/wrap-find-elements-as-global.js — wraps
  compiled output as window.bot.locators.typescript.findElements
- javascript/atoms/test/find_elements_typescript_test.html — QUnit browser
  tests covering all strategies (18 tests)

Build changes:
- javascript/atoms/BUILD.bazel: add tsc compile, strip-semicolon, and
  global-wrap targets; include find-elements-global in atoms filegroup
- javascript/atoms/fragments/BUILD.bazel: add copy_file target
  find-elements-typescript with same visibility as the old closure fragment
- py/BUILD.bazel: switch find-elements src to the TypeScript-generated file

The relative_by_tests-chrome-bidi integration tests pass with the new
implementation.
@selenium-ci selenium-ci added C-py Python Bindings B-atoms JavaScript chunks generated by Google closure B-build Includes scripting, bazel and CI integrations labels May 14, 2026
Comment thread javascript/atoms/typescript/find-elements.ts Fixed
…ashes in className selector

CodeQL flagged two incomplete string escaping issues:

1. cssEscapeId used '\\' replacement string which CodeQL cannot
   statically verify handles backslash input. Switch to a replacement
   function (c) => '\\' + c to make the intent explicit.

2. classNameMany escaped dots in class names but not backslashes first,
   which means a class name like 'foo\\bar' would produce '.foo\\bar'
   where '\\b' is misinterpreted as a CSS backspace escape. Fix by
   escaping backslashes before escaping dots.
@AutomatedTester AutomatedTester merged commit d9cc9ea into trunk May 14, 2026
68 checks passed
@AutomatedTester AutomatedTester deleted the cool-kalam-ecbae2 branch May 14, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

B-atoms JavaScript chunks generated by Google closure B-build Includes scripting, bazel and CI integrations C-py Python Bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants