import os
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
os.environ['PATH']+=os.pathsep+r"C:\Users\faisal\Documents\chromedriver_win32"
location =input("place to go: ")
check_in_date=input("check in date (dd-m-yyyy):")
days=str(input("how many days? ,(max 30): "))
total_guest=input("total guest: ")
driver = webdriver.Chrome()
driver.get("https://www.traveloka.com/")
form=driver.find_element(By.CSS_SELECTOR,'input[placeholder="City, hotel, place to go"]')
form.send_keys("jakarta")
WebDriverWait(driver,30).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR,'div[data-testid="dropdown-menu-item"]')))[0].click()
open_celendar=driver.find_element(By.CSS_SELECTOR,'svg[data-id="IcSystemCalendar"]').click()
check_in=driver.find_element(By.CSS_SELECTOR,f'div[data-testid="date-cell-{check_in_date}"]')
check_in.click()
open_duration=driver.find_element(By.CSS_SELECTOR,'input[data-testid="duration-field"]')
open_duration.click()
driver.implicitly_wait(5)
duration=driver.find_element(By.CSS_SELECTOR,'div.css-1dbjc4n[style="max-height: 325px;"]')
duration_value=duration.find_element(By.CSS_SELECTOR,f'div[data-testid="dropdown-menu-item"]:nth-child({days})').click()
open_guestfield=driver.find_element(By.CSS_SELECTOR,'input[data-testid="occupancy-field"]').click()
add_adult=driver.find_elements(By.CSS_SELECTOR,'div[data-testid="stepper-plus"]')[0]
for i in range(1,int(total_guest)):
add_adult.click()
click_search=driver.find_element(By.CSS_SELECTOR,'div[data-testid="search-submit-button"]').click()
driver.implicitly_wait(30)
items=WebDriverWait(driver,60).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR,'div.ztzlF._2nyWi')))
for item in items:
hotel_name=item.find_element(By.CSS_SELECTOR,'div._1z5je._10ZQX.tvat-hotelName').text
hotel_location=item.find_element(By.CSS_SELECTOR,'div._3tICV').text
hotel_price=item.find_element(By.CSS_SELECTOR,'div._22n9I.tvat-primaryPrice').text
print("hotel name: ",hotel_name)
print('hotel_location: ', hotel_location)
print("hotel_price: ",hotel_price)
driver.quit()