Skip to content

execute_javascript ignores *args, so scripts that use arguments[0] fail #536

Open

Description

@qxf2

Where: core_helpers/selenium_action_objects.py, execute_javascript(self, js_script, *args) (line 375 on the default branch, 13c4604)

What happens: the method takes *args but calls self.driver.execute_script(js_script) without them. Any script that reads arguments[0] (for example, scrolling to or clicking a located element) gets undefined. The error is caught, logged as critical, and the method returns False.

Steps:

  1. In a page object, locate an element: el = self.get_element(locator).
  2. Call self.execute_javascript("arguments[0].scrollIntoView(true);", el).

Expected: the element scrolls into view, and the method returns True.
Actual: a JavaScript error (Cannot read properties of undefined), logged as critical, and the method returns False.

Likely fix: self.driver.execute_script(js_script, *args).

Related: the method returns only a pass/fail flag, so callers can't get the script's return value (e.g. return document.title). That may be intended. Mentioning it in case it isn't.

Found while writing automation with the framework.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions