-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSelenithon.py
58 lines (48 loc) · 1.94 KB
/
Selenithon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import logging
import time
from enum import Enum, auto
from selenium.webdriver import Safari, Firefox, Chrome
from selenium.webdriver.common.action_chains import ActionChains
from GetFunction import GetFuntion
from ActionFunction import ActionFuntion
from CheckFunction import CheckFuntion
logger = logging.getLogger(__name__)
# Time out base on internet connection
TIME_OUT = 3
class WebDriverOption(Enum):
SAFARI = auto()
FIREFOX = auto()
CHROME = auto()
class Selenithon (GetFuntion, ActionFuntion, CheckFuntion):
def __init__(self, webdriver_option: WebDriverOption) -> None:
self.web_driver_option = webdriver_option
self.web_driver = None
self.action = None
def open_website(self, domain: str, timeout_s: int = TIME_OUT):
match self.web_driver_option:
case WebDriverOption.SAFARI:
from selenium.webdriver.safari.options import Options
opts = Options()
opts.add_argument("--headless")
self.web_driver = Safari(options=opts)
pass
case WebDriverOption.FIREFOX:
from selenium.webdriver.firefox.options import Options
opts = Options()
opts.add_argument("--headless")
self.web_driver = Firefox(options=opts)
case WebDriverOption.CHROME:
from selenium.webdriver.chrome.options import Options
opts = Options()
opts.add_argument("--headless")
self.web_driver = Chrome(options=opts)
case _:
logger.error(
"Can not recognize web driver option. Please choose the following option: Safari, Firefor, Chrome")
self.web_driver.get(domain)
self.web_driver.maximize_window()
self.action = ActionChains(self.web_driver)
time.sleep(timeout_s)
def close(self):
self.web_driver.close()
quit()