Skip to content

Commit cf7d0d1

Browse files
committed
Add option for get_attribute() to return None instead of fail
1 parent 463c103 commit cf7d0d1

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ def get_text(self, selector, by=By.CSS_SELECTOR, timeout=None):
794794
return element_text
795795

796796
def get_attribute(self, selector, attribute, by=By.CSS_SELECTOR,
797-
timeout=None):
797+
timeout=None, hard_fail=True):
798798
""" This method uses JavaScript to get the value of an attribute. """
799799
if not timeout:
800800
timeout = settings.SMALL_TIMEOUT
@@ -816,8 +816,11 @@ def get_attribute(self, selector, attribute, by=By.CSS_SELECTOR,
816816
if attribute_value is not None:
817817
return attribute_value
818818
else:
819-
raise Exception("Element {%s} has no attribute {%s}!" % (
820-
selector, attribute))
819+
if hard_fail:
820+
raise Exception("Element {%s} has no attribute {%s}!" % (
821+
selector, attribute))
822+
else:
823+
return None
821824

822825
def set_attribute(self, selector, attribute, value, by=By.CSS_SELECTOR,
823826
timeout=None):

0 commit comments

Comments
 (0)