-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Ocs.py
114 lines (87 loc) · 3.97 KB
/
Ocs.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
from Provider import Provider
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from time import sleep
from faker import Faker
class Ocs(Provider):
def __init__(self, threeScreen):
two_screen = 'https://www.ocs.fr/souscription/creation?offer=999'
three_screen = 'https://www.ocs.fr/souscription/creation?offer=1199'
if threeScreen:
self.base_url = three_screen
else:
self.base_url = two_screen
self.faker = Faker()
options = webdriver.ChromeOptions()
options.add_argument("--headless")
self.browser = webdriver.Chrome(options=options)
super().__init__(browser=self.browser)
def register(self, email, passwd, cbNumber, expireMonth, expireYear, cvv, cardLastName, cardFirstName):
name = self.faker.name()
firstname = name.split(' ')[0]
lastname = name.split(' ')[1]
self.browser.get(self.base_url)
sleep(1)
# Create account
self.scrollToDown()
firstNameEl = self.browser.find_element_by_name("firstname")
firstNameEl.send_keys(firstname)
lastNameEl = self.browser.find_element_by_name("name")
lastNameEl.send_keys(lastname)
emailEl = self.browser.find_element_by_name("email")
emailEl.send_keys(email)
emailConfEl = self.browser.find_element_by_name("email-confirmation")
emailConfEl.send_keys(email)
password = self.browser.find_element_by_name("password")
password.send_keys(passwd)
# Remove cookie overlay
try:
self.browser.find_elements_by_css_selector('button.eu-cookie-compliance-secondary-button')[0].click()
sleep(1)
except Exception as e:
print("Failed to remove cookie overlay")
# Send create account
container = self.browser.find_elements_by_css_selector('div.action')[0]
button = container.find_elements_by_css_selector('button.btn--fill')[0]
button.click()
# Switch to credit card iframe
sleep(2)
iframeContainer = self.browser.find_elements_by_css_selector('div.iframe')[0]
iframe = iframeContainer.find_element_by_id('ocs-activation')
self.browser.switch_to.frame(iframe)
# Fill cb owner name
inputCbOwner = self.browser.find_element_by_name('pai_nom')
inputCbOwner.clear()
inputCbOwner.send_keys(cardLastName + ' ' +cardFirstName)
# Fill cb number
cbNumber = str(cbNumber)
creditCard = self.browser.find_element_by_name("pai_numcb_1")
creditCard.send_keys(cbNumber[0:4])
creditCard = self.browser.find_element_by_name("pai_numcb_2")
creditCard.send_keys(cbNumber[4:8])
creditCard = self.browser.find_element_by_name("pai_numcb_3")
creditCard.send_keys(cbNumber[8:12])
creditCard = self.browser.find_element_by_name("pai_numcb_4")
creditCard.send_keys(cbNumber[12:16])
# cb month
select = Select(self.browser.find_element_by_name('pai_expir_mm'))
select.select_by_value(expireMonth)
# cb year
select = Select(self.browser.find_element_by_name('pai_expir_aa'))
select.select_by_value(expireYear)
# cb code
creditCardCode = self.browser.find_element_by_name("pai_cvc")
creditCardCode.send_keys(cvv)
button = self.browser.find_element_by_id('btn-active-abo')
button.click()
sleep(20)
self.browser.switch_to.default_content()
self.browser.quit()
def cancelSubscription(self):
base_url = 'https://go.ocs.fr/'
self.browser.get(base_url)
sleep(1)
self.browser.find_elements_by_css_selector('span.delete_profil')[0].click()
sleep(1)
self.browser.find_elements_by_css_selector('span.confirm_delete_profil')[0].click()
cancelContainer.find_elements_by_css_selector('button.btn')[0].click()