Skip to content

Instantly share code, notes, and snippets.

@barancev
Created April 1, 2020 12:32
Show Gist options
  • Select an option

  • Save barancev/4eab71a29e2f571d820f12fd7469a6c0 to your computer and use it in GitHub Desktop.

Select an option

Save barancev/4eab71a29e2f571d820f12fd7469a6c0 to your computer and use it in GitHub Desktop.
C:\devel\homework\venv\Scripts\python.exe C:/devel/try-something/py/my_sample.py
[{'kind': 'above', 'args': ['div']}, {'kind': 'above', 'args': ['img']}]
[{'kind': 'above', 'args': ['div']}, {'kind': 'above', 'args': ['img']}]
class RelativeBy(object):
def __init__(self, root=None, filters=[]):
self.root = root
self.filters = filters
def above(self, element_or_locator=None):
self.filters.append({"kind": "above", "args": [element_or_locator]})
return self
def to_dict(self):
return {
'relative': {
'root': self.root,
'filters': self.filters,
}
}
def with_tag_name(tag_name):
return RelativeBy({"css selector": tag_name})
p = with_tag_name("p").above("div")
a = with_tag_name("a").above("img")
print(p.filters)
print(a.filters)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment