-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
75 lines (62 loc) · 2.42 KB
/
main.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
import os
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
import time
time_stamp = time.strftime("%Y%m%d-%H%M%S")
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--disable-notifications")
chrome_options.add_argument("--headless")
chrome_options.add_argument("window-size=1400,800");
s = Service(executable_path='./chromedriver')
driver = webdriver.Chrome(service=s, options=chrome_options)
driver.get('https://www.krc.com.tr/contact-form')
contact_type = Select(driver.find_element(By.ID, 'ChannelId'))
contact_type.select_by_visible_text('E-Ticaret İletişim')
print("Contact type is selected")
complain_type = Select(driver.find_element(By.ID, 'RequestType'))
complain_type.select_by_visible_text('Şikayet')
print("Contact reason is selected")
driver.implicitly_wait(15)
try:
close_overlay = driver.find_element(By.ID, 'vl-form-close')
close_overlay.click()
except:
print("No popup window")
SCROLL_PAUSE_TIME = 0.5
# Get scroll height
last_height = driver.execute_script("return document.body.scrollHeight")
while True:
# Scroll down to bottom
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
# Wait to load page
time.sleep(SCROLL_PAUSE_TIME)
# Calculate new scroll height and compare with last scroll height
new_height = driver.execute_script("return document.body.scrollHeight")
if new_height == last_height:
break
last_height = new_height
fields = {
'custname': 'Ahmet',
'CustSurName': 'Turkmen',
'Email': os.getenv("EMAIL"),
'phone': os.getenv("PHONE_NUMBER"),
'Description': os.getenv("COMPLAIN_MESSAGE")
}
for k, v in fields.items():
driver.find_element(By.ID, k).send_keys(v)
time.sleep(7)
try:
submit = driver.find_element(By.ID, 'customerContactFormSubmitWithRecaptcha')
submit.click()
message = driver.find_element(By.CLASS_NAME,"krc-alert info mb-2").text
if message == "Form Başarıyla Gönderildi":
driver.find_element(By.ID, 'Description').clear() # do not leak message
driver.save_screenshot('contact-page-{}.png'.format(time_stamp))
print(message)
else:
print("Failed to submit form")
except:
driver.find_element(By.ID, 'Description').clear() # do not leak message
driver.save_screenshot('contact-page-{}.png'.format(time_stamp))