SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
29.79k stars 8.02k forks source link

[🐛 Bug]: `a.tagName.toUpperCase is not a function` when input id or name is 'tagName' #14229

Open yoshitaka-ogata opened 3 days ago

yoshitaka-ogata commented 3 days ago

What happened?

node.tagName.toUpperCase() may throw the error because the form tagName returns a child input element instead of the tag name if the input element id or name is 'tagName'.

The error was raised at https://github.com/SeleniumHQ/selenium/blob/c5f314670396b04e92b32500bd6e0dfac31e841f/javascript/atoms/domcore.js#L173

FYI Playwright fixed the same issue. https://github.com/microsoft/playwright/pull/30636

How can we reproduce the issue?

HTML

<form id="aaa">
  <input type="text" name="tagName">
</form>

Python

elm = driver.find_element(by=By.ID, value="aaa")
displayed = elm.is_displayed()

Relevant log output

Traceback (most recent call last):
  File "xxxxxx/selenium/xxxxxx.py", line 20, in <module>
    displayed = elm.is_displayed()
  File "xxxxxx/lib/python3.9/site-packages/selenium/webdriver/remote/webelement.py", line 252, in is_displayed
    return self.parent.execute_script(f"/* isDisplayed */return ({isDisplayed_js}).apply(null, arguments);", self)
  File "xxxxxx/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 414, in execute_script
    return self.execute(command, {"script": script, "args": converted_args})["value"]
  File "xxxxxx/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 354, in execute
    self.error_handler.check_response(response)
  File "xxxxxx/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.JavascriptException: Message: javascript error: a.tagName.toUpperCase is not a function
  (Session info: chrome=126.0.6478.127)

Operating System

macOS

Selenium version

Python selenium 4.22.0

What are the browser(s) and version(s) where you see this issue?

Chrome 126.0.6478.126.0

What are the browser driver(s) and version(s) where you see this issue?

Chrome driver 126.0.6478.126.0

Are you using Selenium Grid?

No response

github-actions[bot] commented 3 days ago

@yoshitaka-ogata, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

diemol commented 2 days ago

I am not sure if the atom is being used by ChromeDriver. I think they have their own implementation.

However, can you help us with a fix through a PR, and we can give you a nightly build to test it? Adding a test to the PR would be ideal. Thank you!

github-actions[bot] commented 2 days ago

This issue is looking for contributors.

Please comment below or reach out to us through our IRC/Slack/Matrix channels if you are interested.

yoshitaka-ogata commented 21 hours ago

Thank you for your comment.

According to the Chromium project's read me, Chrome Driver clones the Selenium repository and builds it by bazel. Therefore, I think it needs to be fixed to resolve the Chrome Driver error.

I'll prepare a PR later.