Skip to content

[🐛 Bug]: Wrong type for WebElement.get_property #10624

@eNcacz

Description

@eNcacz

What happened?

This is similar issue to #10623

In this case it's not so straightforward. The WebElement.get_property declare return value type as str.
It is true in many cases but if you try to get property 'parentElement' (see example below), then the return value is WebElement.
But mypy (PyCharm and other linters) complains that result of get_property is always str.
Can you declare return type of get_property as Union of all possible types, which the method can return?

How can we reproduce the issue?

from chromedriver_binary.utils import get_chromedriver_path
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.remote.webelement import WebElement


def test():
  driver = webdriver.Chrome(executable_path=get_chromedriver_path() + '/chromedriver')
  driver.get('http://www.example.com/')
  element = driver.find_element(by=By.TAG_NAME, value='h1')
  parentElement: WebElement = element.get_property('parentElement')
  print(type(parentElement))


if __name__ == '__main__':
  test()

Relevant log output

no log needed

Operating System

Gentoo Linux

Selenium version

Python 4.1.5

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

not relevant

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

not relevant

Are you using Selenium Grid?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-pyPython BindingsI-defectSomething is not working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions