Repository navigation
Conversation
…ert errors
MobileErrorHandler.check_response passed the whole W3C error `data`
object as `alert_text` when raising UnexpectedAlertPresentException.
For an `unexpected alert open` error with `"data": {"text": "Hello"}`,
`e.alert_text` was `{'text': 'Hello'}` and `str(e)` started with
`Alert Text: {'text': 'Hello'}`. Selenium's own ErrorHandler gives
`'Hello'`.
Take `data['text']` when `data` is a dict, as Selenium does, and use
None otherwise.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When the server returns an
unexpected alert openerror,MobileErrorHandler.check_responsepasses the whole W3Cdataobject toUnexpectedAlertPresentExceptionasalert_text. The W3C spec puts the alert's text indata.text:ErrorHandlere.alert_text{'text': 'Hello'}'Hello'str(e)starts withAlert Text: {'text': 'Hello'}Alert Text: Helloalert_textis meant to be a string, so code that logs it or searches it gets the wrong result.Fix
data['text']whendatais a dict, as Selenium does.Nonewhen there is nodata, or when it is not a dict or has notext.The change is limited to the
UnexpectedAlertPresentExceptionlines at the end ofcheck_response.Behaviour change:
e.alert_textis now the alert's text as a string. Code that worked around the bug withe.alert_text['text']would need updating.Tests
test/unit/webdriver/errorhandler_alert_test.pychecks that:alert_textis'Hello'andstr(e)containsAlert Text: Hellofordata: {'text': 'Hello'};alert_textisNonewhendatais missing or has notext;find_element()raisesUnexpectedAlertPresentExceptionwithalert_text == 'Hello'when the server answers 500 with that error, checked end to end through httpretty.assert {'text': 'Hello'} == 'Hello'.ruff check,ruff format --check,mypy appiumand the full unit test suite pass.🤖 Generated with Claude Code