[🐛 Bug]: Wrong type for WebElement.get_property
See original GitHub issueWhat 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:
- Created a year ago
- Comments:9 (7 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@titusfortner I think this list is not enough. For example
clientHeight
property is returned asint
fooBar
property is returned asNoneType
childNodes
property is returned aslist
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]]
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.