Skip to content

Commit e386473

Browse files
committed
Add remove_attributes() method
1 parent ea02a37 commit e386473

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,25 @@ def remove_attribute(self, selector, attribute, by=By.CSS_SELECTOR,
812812
% (css_selector, attribute))
813813
self.execute_script(script)
814814

815+
def remove_attributes(self, selector, attribute, by=By.CSS_SELECTOR):
816+
""" This method uses JavaScript to remove a common attribute.
817+
All matching selectors from querySelectorAll() are used. """
818+
selector, by = self.__recalculate_selector(selector, by)
819+
attribute = re.escape(attribute)
820+
attribute = self.__escape_quotes_if_needed(attribute)
821+
css_selector = self.convert_to_css_selector(selector, by=by)
822+
css_selector = re.escape(css_selector)
823+
css_selector = self.__escape_quotes_if_needed(css_selector)
824+
script = ("""var $elements = document.querySelectorAll('%s');
825+
var index = 0, length = $elements.length;
826+
for(; index < length; index++){
827+
$elements[index].removeAttribute('%s');}"""
828+
% (css_selector, attribute))
829+
try:
830+
self.execute_script(script)
831+
except Exception:
832+
pass
833+
815834
def get_property_value(self, selector, property, by=By.CSS_SELECTOR,
816835
timeout=settings.SMALL_TIMEOUT):
817836
""" Returns the property value of a page element's computed style.

0 commit comments

Comments
 (0)