(
self, selector, timeout=None, must_be_visible=False
)
| 15128 | # Shadow DOM / Shadow-root methods |
| 15129 | |
| 15130 | def __get_shadow_element( |
| 15131 | self, selector, timeout=None, must_be_visible=False |
| 15132 | ): |
| 15133 | self.wait_for_ready_state_complete() |
| 15134 | if timeout is None: |
| 15135 | timeout = settings.SMALL_TIMEOUT |
| 15136 | elif timeout == 0: |
| 15137 | timeout = 0.1 # Use for: is_shadow_element_* (* = present/visible) |
| 15138 | if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT: |
| 15139 | timeout = self.__get_new_timeout(timeout) |
| 15140 | self.__fail_if_invalid_shadow_selector_usage(selector) |
| 15141 | if "::shadow " not in selector: |
| 15142 | raise Exception( |
| 15143 | 'A Shadow DOM selector must contain at least one "::shadow "!' |
| 15144 | ) |
| 15145 | selectors = selector.split("::shadow ") |
| 15146 | element = self.get_element(selectors[0]) |
| 15147 | selector_chain = selectors[0] |
| 15148 | is_present = False |
| 15149 | for selector_part in selectors[1:]: |
| 15150 | shadow_root = None |
| 15151 | if self.is_chromium() or self.browser == "firefox": |
| 15152 | try: |
| 15153 | shadow_root = element.shadow_root |
| 15154 | except Exception: |
| 15155 | if timeout != 0.1: # Skip wait for special 0.1 (See above) |
| 15156 | time.sleep(2) |
| 15157 | try: |
| 15158 | shadow_root = element.shadow_root |
| 15159 | except Exception: |
| 15160 | raise Exception( |
| 15161 | "Element {%s} has no shadow root!" % selector_chain |
| 15162 | ) |
| 15163 | else: |
| 15164 | try: |
| 15165 | shadow_root = self.execute_script( |
| 15166 | "return arguments[0].shadowRoot;", element |
| 15167 | ) |
| 15168 | except Exception: |
| 15169 | time.sleep(2) |
| 15170 | shadow_root = self.execute_script( |
| 15171 | "return arguments[0].shadowRoot;", element |
| 15172 | ) |
| 15173 | if timeout == 0.1 and not shadow_root: |
| 15174 | raise Exception( |
| 15175 | "Element {%s} has no shadow root!" % selector_chain |
| 15176 | ) |
| 15177 | elif not shadow_root: |
| 15178 | time.sleep(2) # Wait two seconds for the shadow root to appear |
| 15179 | shadow_root = self.execute_script( |
| 15180 | "return arguments[0].shadowRoot;", element |
| 15181 | ) |
| 15182 | if not shadow_root: |
| 15183 | raise Exception( |
| 15184 | "Element {%s} has no shadow root!" % selector_chain |
| 15185 | ) |
| 15186 | selector_chain += "::shadow " |
| 15187 | selector_chain += selector_part |
no test coverage detected