Add webelem.css_selector
This commit is contained in:
parent
121483aa90
commit
0423ec6f91
@ -750,25 +750,16 @@ class HintManager(QObject):
|
||||
raise cmdexc.CommandError("No URL set for this page yet!")
|
||||
self._context.args = args
|
||||
self._context.group = group
|
||||
selector = self._get_selector()
|
||||
|
||||
try:
|
||||
selector = webelem.css_selector(self._context.group,
|
||||
self._context.baseurl)
|
||||
except webelem.Error as e:
|
||||
raise cmdexc.CommandError(str(e))
|
||||
|
||||
self._context.tab.elements.find_css(selector, self._start_cb,
|
||||
only_visible=True)
|
||||
|
||||
def _get_selector(self):
|
||||
"""Get the CSS selectors for this url and hinting group."""
|
||||
url = self._context.baseurl
|
||||
group = self._context.group
|
||||
|
||||
selectors = config.instance.get('hints.selectors', url)
|
||||
if group not in selectors:
|
||||
selectors = config.val.hints.selectors
|
||||
|
||||
if group not in selectors:
|
||||
raise cmdexc.CommandError("Undefined hinting group "
|
||||
"'{}'!".format(group))
|
||||
|
||||
return ','.join(selectors[group])
|
||||
|
||||
def current_mode(self):
|
||||
"""Return the currently active hinting mode (or None otherwise)."""
|
||||
if self._context is None:
|
||||
|
@ -150,6 +150,9 @@ def prevnext(*, browsertab, win_id, baseurl, prev=False,
|
||||
else:
|
||||
browsertab.openurl(url)
|
||||
|
||||
selectors = config.instance.get('hints.selectors', baseurl)
|
||||
link_selector = ','.join(selectors['links'])
|
||||
try:
|
||||
link_selector = webelem.css_selector('links', baseurl)
|
||||
except webelem.Error as e:
|
||||
raise Error(str(e))
|
||||
|
||||
browsertab.elements.find_css(link_selector, _prevnext_cb)
|
||||
|
@ -44,6 +44,18 @@ class OrphanedError(Error):
|
||||
pass
|
||||
|
||||
|
||||
def css_selector(group, url):
|
||||
"""Get a CSS selector for the given group/URL."""
|
||||
selectors = config.instance.get('hints.selectors', url)
|
||||
if group not in selectors:
|
||||
selectors = config.val.hints.selectors
|
||||
|
||||
if group not in selectors:
|
||||
raise Error("Undefined hinting group {!r}".format(group))
|
||||
|
||||
return ','.join(selectors[group])
|
||||
|
||||
|
||||
class AbstractWebElement(collections.abc.MutableMapping):
|
||||
|
||||
"""A wrapper around QtWebKit/QtWebEngine web element.
|
||||
|
@ -192,7 +192,7 @@ Feature: Using hints
|
||||
Scenario: Error with invalid hint group
|
||||
When I open data/hints/buttons.html
|
||||
And I run :hint INVALID_GROUP
|
||||
Then the error "Undefined hinting group 'INVALID_GROUP'!" should be shown
|
||||
Then the error "Undefined hinting group 'INVALID_GROUP'" should be shown
|
||||
|
||||
Scenario: Custom hint group
|
||||
When I open data/hints/custom_group.html
|
||||
|
@ -80,6 +80,11 @@ Feature: Using :navigate
|
||||
And I run :navigate next
|
||||
Then the error "SyntaxError: Failed to execute 'querySelectorAll' on 'Document': '@' is not a valid selector." should be shown
|
||||
|
||||
Scenario: Navigating with no next selector
|
||||
When I set hints.selectors to {'all': ['a']}
|
||||
And I run :navigate next
|
||||
Then the error "Undefined hinting group 'links'" should be shown
|
||||
|
||||
# increment/decrement
|
||||
|
||||
Scenario: Incrementing number in URL
|
||||
|
Loading…
Reference in New Issue
Block a user