|
33 | 33 |
|
34 | 34 | # TODO: When moving to supporting python 3.9 as the minimum version we can |
35 | 35 | # use built in importlib_resources.files. |
36 | | -_pkg = '.'.join(__name__.split('.')[:-1]) |
37 | | -getAttribute_js = pkgutil.get_data(_pkg, 'getAttribute.js').decode('utf8') |
38 | | -isDisplayed_js = pkgutil.get_data(_pkg, 'isDisplayed.js').decode('utf8') |
| 36 | +getAttribute_js = None |
| 37 | +isDisplayed_js = None |
| 38 | + |
| 39 | + |
| 40 | +def _load_js(): |
| 41 | + global getAttribute_js |
| 42 | + global isDisplayed_js |
| 43 | + _pkg = '.'.join(__name__.split('.')[:-1]) |
| 44 | + getAttribute_js = pkgutil.get_data(_pkg, 'getAttribute.js').decode('utf8') |
| 45 | + isDisplayed_js = pkgutil.get_data(_pkg, 'isDisplayed.js').decode('utf8') |
39 | 46 |
|
40 | 47 |
|
41 | 48 | class BaseWebElement(metaclass=ABCMeta): |
@@ -151,7 +158,8 @@ def get_attribute(self, name) -> str: |
151 | 158 | is_active = "active" in target_element.get_attribute("class") |
152 | 159 |
|
153 | 160 | """ |
154 | | - |
| 161 | + if getAttribute_js is None: |
| 162 | + _load_js() |
155 | 163 | attribute_value = self.parent.execute_script( |
156 | 164 | "return (%s).apply(null, arguments);" % getAttribute_js, |
157 | 165 | self, name) |
@@ -591,6 +599,8 @@ def shadow_root(self) -> ShadowRoot: |
591 | 599 | def is_displayed(self) -> bool: |
592 | 600 | """Whether the element is visible to a user.""" |
593 | 601 | # Only go into this conditional for browsers that don't use the atom themselves |
| 602 | + if isDisplayed_js is None: |
| 603 | + _load_js() |
594 | 604 | return self.parent.execute_script( |
595 | 605 | "return (%s).apply(null, arguments);" % isDisplayed_js, |
596 | 606 | self) |
|
0 commit comments