Skip to content

Commit 286f5f4

Browse files
author
ravishankar
committed
#10 resolved project structure
1 parent 033161e commit 286f5f4

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

s_tool/driver.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from webdriver_manager.firefox import GeckoDriverManager
66
from webdriver_manager.utils import ChromeType
77

8+
from s_tool.exceptions import SToolException
89
from s_tool.utils import (
9-
SToolException,
1010
click,
1111
current_url,
1212
get_cookies,
@@ -93,8 +93,4 @@ def _load_methods(self):
9393

9494

9595
if __name__ == "__main__":
96-
97-
# Create A Driver Object
98-
with SeleniumDriver("firefox", headless=False) as obj:
99-
# visit https:example.com
100-
obj.visit(r"https://quotes.toscrape.com/")
96+
pass

s_tool/exceptions.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class SToolException(Exception):
2+
"""
3+
Base Class for selenium tools Exceptions
4+
"""
5+
6+
def __init__(self, message):
7+
self.message = message
8+
9+
def __str__(self):
10+
return str(self.message)

s_tool/parser.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
1-
class Parser(object):
2-
"""Parse data from webdriver"""
1+
from s_tool.utils import get_element
32

4-
def __init__(self, driver):
5-
self.driver = driver
3+
4+
def select_options(element, swap=None, text_exclude=[]):
5+
"""Return dropdown option in key value pair
6+
7+
Args:
8+
element : An select element
9+
text_exclude : list of values to exclude from result
10+
11+
Returns:
12+
return dict of values and text of select element,
13+
return empty dict() if element is not valid or not exists
14+
"""
15+
option_dict = dict()
16+
if element and hasattr(element, "tag_name") and element.tag_name == "select":
17+
options = get_element(element, "tag_name", "option", many=True)
18+
for option in options:
19+
func = option.get_attribute
20+
text, value = func("text"), func("value")
21+
if text not in text_exclude:
22+
if swap:
23+
text, value = value, text
24+
option_dict[value] = text
25+
26+
return option_dict

0 commit comments

Comments
 (0)