Represents a DOM element. Generally, all interesting operations that interact with a document will be performed through this interface. All method calls will do a freshness check to ensure that the element reference is still valid. This essentially determines whether the eleme
| 59 | |
| 60 | |
| 61 | class WebElement(BaseWebElement): |
| 62 | """Represents a DOM element. |
| 63 | |
| 64 | Generally, all interesting operations that interact with a document will be |
| 65 | performed through this interface. |
| 66 | |
| 67 | All method calls will do a freshness check to ensure that the element |
| 68 | reference is still valid. This essentially determines whether the |
| 69 | element is still attached to the DOM. If this test fails, then an |
| 70 | `StaleElementReferenceException` is thrown, and all future calls to this |
| 71 | instance will fail. |
| 72 | """ |
| 73 | |
| 74 | def __init__(self, parent, id_) -> None: |
| 75 | self._parent = parent |
| 76 | self._id = id_ |
| 77 | |
| 78 | def __repr__(self): |
| 79 | return f'<{type(self).__module__}.{type(self).__name__} (session="{self.session_id}", element="{self._id}")>' |
| 80 | |
| 81 | @property |
| 82 | def session_id(self) -> str: |
| 83 | return self._parent.session_id |
| 84 | |
| 85 | @property |
| 86 | def tag_name(self) -> str: |
| 87 | """This element's `tagName` property. |
| 88 | |
| 89 | Returns: |
| 90 | The tag name of the element. |
| 91 | |
| 92 | Example: |
| 93 | element = driver.find_element(By.ID, "foo") |
| 94 | """ |
| 95 | return self._execute(Command.GET_ELEMENT_TAG_NAME)["value"] |
| 96 | |
| 97 | @property |
| 98 | def text(self) -> str: |
| 99 | """The text of the element. |
| 100 | |
| 101 | Returns: |
| 102 | The text of the element. |
| 103 | |
| 104 | Example: |
| 105 | element = driver.find_element(By.ID, "foo") |
| 106 | print(element.text) |
| 107 | """ |
| 108 | return self._execute(Command.GET_ELEMENT_TEXT)["value"] |
| 109 | |
| 110 | def click(self) -> None: |
| 111 | """Clicks the element. |
| 112 | |
| 113 | Example: |
| 114 | element = driver.find_element(By.ID, "foo") |
| 115 | element.click() |
| 116 | """ |
| 117 | self._execute(Command.CLICK_ELEMENT) |
| 118 |
no outgoing calls