Add is_link method to webelem

This commit is contained in:
Jay Kamat 2017-05-08 22:00:11 -07:00
parent 6c3f29d570
commit e07a1045a8
No known key found for this signature in database
GPG Key ID: 5D2E399600F4F7B5
2 changed files with 8 additions and 5 deletions

View File

@ -306,6 +306,11 @@ class AbstractWebElement(collections.abc.MutableMapping):
qtutils.ensure_valid(url)
return url
def is_link(self):
"""Return True if this AbstractWebElement is a link."""
href_tags = ['a', 'area', 'link']
return self.tag_name() in href_tags
def _mouse_pos(self):
"""Get the position to click/hover."""
# Click the center of the largest square fitting into the top/left
@ -403,9 +408,8 @@ class AbstractWebElement(collections.abc.MutableMapping):
self._click_fake_event(click_target)
return
href_tags = ['a', 'area', 'link']
if click_target == usertypes.ClickTarget.normal:
if self.tag_name() in href_tags:
if self.is_link():
log.webelem.debug("Clicking via JS click()")
self._click_js(click_target)
elif self.is_editable(strict=True):
@ -418,7 +422,7 @@ class AbstractWebElement(collections.abc.MutableMapping):
elif click_target in [usertypes.ClickTarget.tab,
usertypes.ClickTarget.tab_bg,
usertypes.ClickTarget.window]:
if self.tag_name() in href_tags:
if self.is_link():
self._click_href(click_target)
else:
self._click_fake_event(click_target)

View File

@ -285,8 +285,7 @@ class WebKitElement(webelem.AbstractWebElement):
for _ in range(5):
if elem is None:
break
tag = elem.tag_name()
if tag == 'a' or tag == 'area':
if elem.is_link():
if elem.get('target', None) == '_blank':
elem['target'] = '_top'
break