Skip to content

Commit 9941c81

Browse files
committed
Add docstrings to __repr__, __eq__, __ne__, and __hash__ methods in WebElement class for clarity on functionality
1 parent 0b847d1 commit 9941c81

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

py/selenium/webdriver/remote/webelement.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ def __init__(self, parent, id_) -> None:
7373
self._id = id_
7474

7575
def __repr__(self):
76+
"""Return a string representation of the WebElement object.
77+
78+
Returns:
79+
A string representation showing the module, class name, session ID,
80+
and element ID.
81+
"""
7682
return f'<{type(self).__module__}.{type(self).__name__} (session="{self.session_id}", element="{self._id}")>'
7783

7884
@property
@@ -488,10 +494,26 @@ def id(self) -> str:
488494
"""
489495
return self._id
490496

491-
def __eq__(self, element):
497+
def __eq__(self, element) -> bool:
498+
"""Compare this WebElement with another element for equality.
499+
500+
Args:
501+
element: The element to compare with.
502+
503+
Returns:
504+
True if both elements have the same ID, False otherwise.
505+
"""
492506
return hasattr(element, "id") and self._id == element.id
493507

494-
def __ne__(self, element):
508+
def __ne__(self, element) -> bool:
509+
"""Compare this WebElement with another element for inequality.
510+
511+
Args:
512+
element: The element to compare with.
513+
514+
Returns:
515+
True if the elements are not equal, False otherwise.
516+
"""
495517
return not self.__eq__(element)
496518

497519
# Private Methods
@@ -559,6 +581,11 @@ def find_elements(self, by=By.ID, value=None) -> list[WebElement]:
559581
return self._execute(Command.FIND_CHILD_ELEMENTS, {"using": by, "value": value})["value"]
560582

561583
def __hash__(self) -> int:
584+
"""Return the hash code for this WebElement.
585+
586+
Returns:
587+
The integer hash of the WebElement ID.
588+
"""
562589
return int(md5_hash(self._id.encode("utf-8")).hexdigest(), 16)
563590

564591
def _upload(self, filename):

0 commit comments

Comments
 (0)