Skip to content

Commit f415771

Browse files
miraoclaude
andcommitted
fix(ElementNotFound): skip page hints in Appium native context (#5812)
Collecting hints ran JavaScript through executeScript, which UiAutomator2 rejects in native context, logging an ERROR line and adding an extra request on every not-found lookup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 402fbb9 commit f415771

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎lib/helper/errors/ElementNotFound.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ElementNotFound extends Error {
4141
try {
4242
const { default: Container } = await import('../../container.js')
4343
const helper = Object.values(Container.helpers()).find(h => h && typeof h.executeScript === 'function')
44-
if (!helper) return null
44+
if (!helper || helper.isWeb === false) return null
4545
const timeout = new Promise(resolve => {
4646
timer = setTimeout(() => resolve(null), 500)
4747
})

‎test/unit/helper/element_not_found_test.js‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ describe('ElementNotFound error', () => {
4949
expect(err.stack).to.include('similar on page: #email')
5050
})
5151

52+
it('should not run the page script in a native app context', async () => {
53+
let called = false
54+
Container.append({ helpers: { Appium: { isWeb: false, executeScript: async () => { called = true } } } })
55+
const err = new ElementNotFound('Sign in')
56+
await err.explain()
57+
expect(called).to.equal(false)
58+
expect(err.message).to.equal('Element "Sign in" was not found by text|CSS|XPath')
59+
})
60+
5261
it('should keep the message when the page script fails', async () => {
5362
Container.append({ helpers: { web: { executeScript: async () => { throw new Error('page closed') } } } })
5463
const err = new ElementNotFound('Sign in')

0 commit comments

Comments
 (0)