question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[🐛 Bug]: Wrong type for WebElement.get_property

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
eNcaczcommented, May 12, 2022

@titusfortner I think this list is not enough. For example

  • clientHeight property is returned as int
  • fooBar property is returned as NoneType
  • childNodes property is returned as list

Just put these names to the example above to test it.

So I think it will be better to use Optional[Union[str, int, bool, WebElement, dict, list]]

0reactions
github-actions[bot]commented, Jun 19, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug with selenium java & chromedriver 77 on element ...
A simple code who worked perfectly doesn't work anymore, because element.getAttribute('id') returns null instead of the string value of id ...
Read more >
The method click() is undefined for the type Object - Software ...
While reading repository properties file getting error response as: The method click() is undefined for the type Object ... Properties obj = new ......
Read more >
Not able to enter the data in numeric field through Webdriver ...
I am not able to enter the data in numeric field, it is giving the error message as "Element must not be hidden,...
Read more >
Interface WebElement - Selenium
Modifier and Type, Method, Description. void, clear(). If this element is a form entry element, this will reset its value. void, click().
Read more >
Shadow DOM in Selenium - Titus on Testing
I've seen numerous bugs reported for how Chrome v96 has changed the ... which will not cast to WebElement , so you'll get...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found