Created
April 1, 2020 12:32
-
-
Save barancev/4eab71a29e2f571d820f12fd7469a6c0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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']}] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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