-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm_enquiry_test.py
79 lines (57 loc) · 3.12 KB
/
m_enquiry_test.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
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
import time
import datetime
from dateutil.relativedelta import relativedelta
startDate = datetime.datetime.now() + relativedelta(years=2)
endDate = startDate + relativedelta(days=2)
# Create a new instance of the Firefox driver
options = Options()
options.add_argument("--headless")
driver = webdriver.Firefox(firefox_options=options)
driver.set_window_size(1024, 768)
startDateString = '"'+ str(startDate.strftime("%d"))+' '+ str(startDate.strftime("%b"))+' '+ str(startDate.strftime("%Y")) + '"'
endDateString = '"'+ str(endDate.strftime("%d"))+' '+ str(endDate.strftime("%b"))+' '+ str(endDate.strftime("%Y")) + '"'
# go to the google home page
driver.get("https://m.travelground.com/accommodation/karoo-ground-selenium-test/enquiry")
#driver.get("http://m.tg.n-al.vm/accommodation/karoo-ground-selenium-test/enquiry")
driver.execute_script ("document.getElementById('enquiry-start-date').setAttribute('data', 'date: "+ startDateString +"' );")
driver.execute_script ("document.getElementById('enquiry-end-date').setAttribute('data', 'date: "+ endDateString +"');")
driver.execute_script ("startDate.setDate("+ startDateString +" );")
driver.execute_script ("endDate.setDate("+ endDateString +" );")
# the page is ajaxy so the title is originally this:
print (driver.title)
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID,"spinner-container")))
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CLASS_NAME,"room-select")))
select = Select(driver.find_element_by_class_name("room-select"))
select.select_by_visible_text("1")
select = Select(driver.find_element_by_class_name("adult-select"))
select.select_by_visible_text(str(datetime.datetime.now().hour))
driver.execute_script ("$('.btn-continue').click();")
print ('date and pax submitted')
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.ID,"enquiry-firstname"))) #this doesn't work with the damn phantom driver
inputElement = driver.find_element_by_id("enquiry-firstname")
inputElement.send_keys("Test")
inputElement = driver.find_element_by_id("enquiry-surname")
inputElement.send_keys("Test")
inputElement = driver.find_element_by_id("enquiry-email")
inputElement.send_keys("[email protected]")
inputElement = driver.find_element_by_id("enquiry-phone")
inputElement.send_keys("1111111111")
inputElement = driver.find_element_by_id("enquiry-message")
inputElement.send_keys("1111111111")
driver.execute_script ("$('.btn-continue').click();")
driver.find_element_by_css_selector('#contact-details .btn-continue').click()
print ('contact info submitted')
print (driver.title)
try:
WebDriverWait(driver, 10).until(EC.title_contains("Success!"))
print (driver.title)
finally:
driver.quit()