本文整理汇总了Python中widgetastic.xpath.quote函数的典型用法代码示例。如果您正苦于以下问题:Python quote函数的具体用法?Python quote怎么用?Python quote使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了quote函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _construct_xpath
def _construct_xpath(path, by_id=False):
items = []
for item in path:
if by_id:
items.append('ul/li[@id={}]'.format(quote(item)))
else:
items.append('ul/li[./span/a[normalize-space(.)={}]]'.format(quote(item)))
return './' + '/'.join(items)
示例2: __init__
def __init__(self, parent, *text, **kwargs):
logger = kwargs.pop('logger', None)
Widget.__init__(self, parent, logger=logger)
if text:
if kwargs:
raise TypeError('If you pass button text then do not pass anything else.')
if len(text) == 1:
self.locator_conditions = 'normalize-space(.)={}'.format(quote(text[0]))
elif len(text) == 2 and text[0].lower() == 'contains':
self.locator_conditions = 'contains(normalize-space(.), {})'.format(quote(text[1]))
else:
raise TypeError('An illegal combination of text params')
else:
# Join the kwargs
self.locator_conditions = ' and '.join(
'@{}={}'.format(attr, quote(value)) for attr, value in kwargs.items())
示例3: __init__
def __init__(self, parent, label=None, id=None, locator=None, logger=None):
Widget.__init__(self, parent, logger=logger)
quoted_label = quote(label) if label else ""
if label:
label_part = " and @label={} or @aria-label={}".format(quoted_label, quoted_label)
else:
label_part = ""
id_part = " and @id={}".format(quote(id)) if id else ""
if locator is not None:
self.locator = locator
elif label_part or id_part:
self.locator = self.LOCATOR_START.format(label_part + id_part)
else:
raise TypeError("You need to specify either, id, label or locator for Navigation")
示例4: __init__
def __init__(self, parent, button_id=None, logger=None):
super(Kebab, self).__init__(parent, logger=logger)
if button_id is not None:
self.locator = (
'.//div[contains(@class, "dropdown-kebab-pf") and ./button[@id={}]]'.format(
quote(button_id)))
else:
self.locator = './/div[contains(@class, "dropdown-kebab-pf") and ./button][1]'
示例5: selected
def selected(self):
names = self.button_names
for name in names:
bttn = self.browser.element(self.BUTTON.format(quote(name)))
if bttn.get_attribute('checked') is not None:
return name
else:
return names[0]
示例6: __init__
def __init__(self, parent, id=None, locator=None, logger=None):
"""Create the widget"""
Widget.__init__(self, parent, logger=logger)
if id:
self.locator = self.BASE_LOCATOR.format(quote(id))
elif locator:
self.locator = locator
else:
raise TypeError("You need to specify either id or locator")
示例7: child_items
def child_items(self, id, ids=False):
self.expand_id(id)
items = self.browser.elements('.//li[@id={}]/ul/li'.format(quote(id)), parent=self)
result = []
for item in items:
if ids:
result.append(self.browser.get_attribute('id', item))
else:
text_item = self.browser.element('./span/a', parent=item)
result.append(self.browser.text(text_item))
return result
示例8: __locator__
def __locator__(self):
if self.locator:
return self.locator
elif self.text:
return (
'.//div[contains(@class, "pf-c-dropdown") and '
"child::button[normalize-space(.)={}]]"
).format(quote(self.text))
else:
return (
'.//div[contains(@class, "pf-c-dropdown")]'
)
示例9: select
def select(self, *levels, **kwargs):
"""Select an item in the navigation.
Args:
*levels: Items to be clicked in the navigation.
Keywords:
anyway: Default behaviour is that if you try selecting an already selected item, it will
not do it. If you pass ``anyway=True``, it will click it anyway.
"""
levels = list(levels)
self.logger.info('Selecting %r in navigation', levels)
anyway = kwargs.pop('anyway', True)
if levels == self.currently_selected and not anyway:
return
passed_levels = []
current_div = self.get_child_div_for(*passed_levels)
for level in levels:
passed_levels.append(level)
finished = passed_levels == levels
link = self.browser.element(
self.DIV_LINKS_MATCHING.format(txt=quote(level)), parent=current_div)
expands = bool(
self.browser.elements(self.SUB_LEVEL, parent=link))
if expands and not finished:
self.logger.debug('moving to %s to open the next level', level)
self.browser.move_to_element(link)
@wait_for_decorator(timeout='10s', delay=0.2)
def other_div_displayed():
return 'is-hover' in self.browser.classes(
self.MATCHING_LI_FOR_DIV.format(quote(level)),
parent=current_div)
# The other child div should be displayed
current_div_width = current_div.size['width']
new_div = self.get_child_div_for(*passed_levels)
# We need to generate a correct stroke to a neighbouring div
new_div_width = new_div.size['width']
mouse_stroke_x = (current_div_width / 2) + (new_div_width / 2)
self.logger.debug('moving mouse by %d px right to the next level', mouse_stroke_x)
self.browser.move_by_offset(mouse_stroke_x, 0)
current_div = new_div
elif not expands and not finished:
raise ValueError(
'You are trying to expand {!r} which cannot be expanded'.format(passed_levels))
else:
# finished
self.logger.debug('finishing the menu selection by clicking on %s', level)
self.browser.click(link)
self.browser.handle_alert(wait=2.0, squash=True)
示例10: item_element
def item_element(self, item, close=True):
"""Returns a WebElement for given item name."""
try:
self.open()
result = self.browser.element(self.ITEM_LOCATOR.format(quote(item)))
if close:
self.close()
return result
except NoSuchElementException:
raise SelectItemNotFound(
"Item {!r} not found in {}. Available items: {}".format(
item, repr(self), self.items
)
)
示例11: select
def select(self, item, close=True):
"""Select a specific item from the kebab.
Args:
item: Item to be selected.
close: Whether to close the kebab after selection. If the item is a link, you may want
to set this to ``False``
"""
try:
self.open()
self.browser.click(self.ITEM.format(quote(item)))
finally:
if close:
self.close()
示例12: checkbox_by_text
def checkbox_by_text(self, text):
"""Returns checkbox's WebElement searched by its text."""
if self._access_func is not None:
for cb in self.checkboxes:
txt = self._access_func(cb)
if txt == text:
return cb
else:
raise NameError("Checkbox with text {} not found!".format(text))
else:
# Has to be only single
return Checkbox(
self,
locator=".//*[normalize-space(.)={}]/input[@type='checkbox']".format(quote(text))
)
示例13: _format_generator
def _format_generator(self, dimmed=False, include_dimmed_alt=False):
"""Generates a dict that will be passed to the formatting strings."""
d = {}
for key, value in self.Button.__dict__.iteritems():
if not key.startswith("_"):
d[key] = value
d["ALT_EXPR"] = self.alt_expr(dimmed=dimmed)
if include_dimmed_alt:
d["DIMMED_ALT"] = quoteattr(self._dimmed_alt or self._alt)
if self._classes:
d['CLASSES'] = 'and ({})'.format(
' and '.join('contains(@class, {})'.format(quote(kls)) for kls in self._classes))
else:
d['CLASSES'] = ''
return d
示例14: nav_links
def nav_links(self, *levels):
if not levels:
return [self.browser.text(el) for el in self.browser.elements(self.ITEMS)]
current_item = self
for i, level in enumerate(levels):
li = self.browser.element(self.ITEM_MATCHING.format(quote(level)), parent=current_item)
try:
current_item = self.browser.element(self.SUB_ITEMS_ROOT, parent=li)
except NoSuchElementException:
if i == len(levels) - 1:
return []
else:
raise
return [
self.browser.text(el) for el in self.browser.elements(self.ITEMS, parent=current_item)
]
示例15: select
def select(self, *levels, **kwargs):
"""Select an item in the navigation.
Args:
*levels: Items to be clicked in the navigation.
force: Force navigation to happen, defaults to False.
"""
self.logger.info("Selecting %r in navigation", levels)
force = kwargs.get("force", False)
if not force and list(levels) == self.currently_selected:
return
current_item = self
for i, level in enumerate(levels, 1):
li = self.browser.element(self.ITEM_MATCHING.format(quote(level)), parent=current_item)
self.browser.click(li)
if i == len(levels):
return
current_item = self.browser.element(self.SUB_ITEMS_ROOT, parent=li)