@@ -1403,6 +1403,50 @@ def remove_attributes(self, selector, attribute, by=By.CSS_SELECTOR):
1403
1403
except Exception:
1404
1404
pass
1405
1405
1406
+ def get_property(
1407
+ self, selector, property, by=By.CSS_SELECTOR, timeout=None
1408
+ ):
1409
+ """Returns the property value of an element.
1410
+ This is not the same as self.get_property_value(), which returns
1411
+ the value of an element's computed style using a different algorithm.
1412
+ If no result is found, an empty string (instead of None) is returned.
1413
+ Example:
1414
+ html_text = self.get_property(SELECTOR, "textContent")
1415
+ """
1416
+ self.__check_scope()
1417
+ if not timeout:
1418
+ timeout = settings.SMALL_TIMEOUT
1419
+ if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
1420
+ timeout = self.__get_new_timeout(timeout)
1421
+ selector, by = self.__recalculate_selector(selector, by)
1422
+ self.wait_for_ready_state_complete()
1423
+ time.sleep(0.01)
1424
+ element = page_actions.wait_for_element_present(
1425
+ self.driver, selector, by, timeout
1426
+ )
1427
+ try:
1428
+ property_value = element.get_property(property)
1429
+ except (StaleElementReferenceException, ENI_Exception):
1430
+ self.wait_for_ready_state_complete()
1431
+ time.sleep(0.14)
1432
+ element = page_actions.wait_for_element_present(
1433
+ self.driver, selector, by, timeout
1434
+ )
1435
+ property_value = element.get_property(property)
1436
+ if not property_value:
1437
+ return ""
1438
+ return property_value
1439
+
1440
+ def get_text_content(self, selector, by=By.CSS_SELECTOR, timeout=None):
1441
+ """Returns the text that appears in the HTML for an element.
1442
+ This is different from "self.get_text(selector, by=By.CSS_SELECTOR)"
1443
+ because that only returns the visible text on a page for an element,
1444
+ rather than the HTML text that's being returned from this method."""
1445
+ self.__check_scope()
1446
+ return self.get_property(
1447
+ selector, property="textContent", by=by, timeout=timeout
1448
+ )
1449
+
1406
1450
def get_property_value(
1407
1451
self, selector, property, by=By.CSS_SELECTOR, timeout=None
1408
1452
):
0 commit comments