diff --git a/qutebrowser/browser/webelem.py b/qutebrowser/browser/webelem.py index f56f20a0b..df481b98c 100644 --- a/qutebrowser/browser/webelem.py +++ b/qutebrowser/browser/webelem.py @@ -288,7 +288,7 @@ class WebElementWrapper(collections.abc.MutableMapping): def remove_blank_target(self): """Remove target from link.""" elem = self._elem - for i in range(5): + for _ in range(5): if elem is None: break tag = elem.tagName().lower() diff --git a/tests/unit/browser/test_webelem.py b/tests/unit/browser/test_webelem.py index 879a7830e..d0e30f5bb 100644 --- a/tests/unit/browser/test_webelem.py +++ b/tests/unit/browser/test_webelem.py @@ -347,11 +347,16 @@ class TestWebElementWrapper: elem_child.remove_blank_target() assert elem._elem.attribute('target') == '_top' - elem = get_webelem(tagname='button') - elem_child = get_webelem(tagname='div', parent=elem._elem) - elem_child._elem.encloseWith(elem._elem) - elem_child.remove_blank_target() - assert 'target' not in elem_child + elem[0] = get_webelem(tagname='div') + for i in range(1, 5): + elem[i] = get_webelem(tagname='div', parent=elem[i-1]) + elem[i]._elem.encloseWith(elem[i-1]._elem) + elem[4].remove_blank_target() + for i in range(5): + assert 'target' not in elem[i] + + elem = get_webelem(tagname='div') + elem.remove_blank_target() assert 'target' not in elem