select destination textbox by id
selection first option with css selector
destination is filled in
#Booking/booking.py
from time import sleep
import Booking.constants as constants
import os
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
class Booking(webdriver.Chrome):
def __init__(self, path=r"C:/Users/zchen/PycharmProjects/selenium", auto_close=True):
self.driver_path = path
self.auto_close = auto_close
os.environ['PATH'] += self.driver_path
super(Booking, self).__init__()
def __exit__(self, exc_type, exc_val, exc_tb):
if self.auto_close:
print('exiting...')
self.quit()
def open_page(self):
self.get(constants.BASE_URL)
print(constants.BASE_URL, 'is opened')
def change_currency(self, currency=None):
currency_element = self.find_element(
By.CSS_SELECTOR,
'button[data-tooltip-text="Choose your currency"]'
)
currency_element.click()
WebDriverWait(self, 30).until(
EC.presence_of_element_located(
(
By.CSS_SELECTOR,
f'a[data-modal-header-async-url-param*={currency}]'
)
)
)
selected_currency_element = self.find_element(
By.CSS_SELECTOR,
f'a[data-modal-header-async-url-param*={currency}]'
)
selected_currency_element.click()
def select_place_to_go(self, place_to_go):
search_field = self.find_element(
By.ID,
"ss"
)
search_field.clear()
search_field.send_keys(place_to_go)
WebDriverWait(self, 30).until(
EC.presence_of_element_located(
(
By.CSS_SELECTOR,
'li[data-i="0"]'
)
)
)
first_result = self.find_element(
By.CSS_SELECTOR,
'li[data-i="0"]'
)
first_result.click()
reference:
No comments:
Post a Comment