Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/dropdown select #22

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 66 additions & 33 deletions vfs_appointment_bot/vfs_bot/vfs_bot_de.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,38 +102,71 @@ def check_for_appontment(
"""
page.get_by_role("button", name="Start New Booking").click()
# Select Visa Centre
visa_centre_dropdown = page.locator("//mat-form-field/div/div/div[3]")
visa_centre_dropdown = page.wait_for_selector('mat-form-field')

# Click on the mat-form-field to open the dropdown
visa_centre_dropdown.click()
visa_centre_option = page.locator(
f"//mat-option[starts-with(@id,'mat-option-')]/span[contains(text(), '{appointment_params.visa_center}')]"
)
visa_centre_option.click()

# Select Category
category_dropdown = page.locator("//div[@id='mat-select-value-3']")
category_dropdown.click()
category_option = page.locator(
f"//mat-option[starts-with(@id,'mat-option-')]/span[contains(text(), '{appointment_params.visa_category}')]"
)
category_option.click()

# Select Subcategory
subcategory_dropdown = page.locator("//div[@id='mat-select-value-5']")
subcategory_dropdown.click()
subcategory_option = page.locator(
f"//mat-option[starts-with(@id,'mat-option-')]/span[contains(text(), '{appointment_params.visa_sub_category}')]"
)
subcategory_option.click()

appointment_date_element = page.locator("//div[4]/div")
date_text = appointment_date_element.text
if (
len(date_text) != 0
and date_text != "No appointment slots are currently available"
and date_text
!= "Currently No slots are available for selected category, please confirm waitlist\nTerms and Conditions"
):
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime("%Y-%m-%d %H:%M:%S")
return [f"message = {date_text} at {st}"]

# Wait for the dropdown options to appear
page.wait_for_selector('mat-option')

# Select the option by its text
visa_centre_dropdown_option = page.wait_for_selector('mat-option:has-text("New Delhi - Visa Application Centre")')
visa_centre_dropdown_option.click()

# page.select_option('mat-option', label='New Delhi - Visa Application Centre')
# visa_centre_option = page.locator(
# f"//mat-option[starts-with(@id,'mat-option-')]/span[contains(text(), '{appointment_params.visa_center}')]"
# )
# visa_centre_option.click()

# # Select Category
# category_dropdown = page.locator("//div[@id='mat-select-value-3']")
# category_dropdown.click()
# category_option = page.locator(
# f"//mat-option[starts-with(@id,'mat-option-')]/span[contains(text(), '{appointment_params.visa_category}')]"
# )
# category_option.click()
# Select Visa Category
visa_category_dropdown = page.query_selector_all('mat-form-field')[1]

visa_category_dropdown.click()

# Wait for the dropdown options to appear
page.wait_for_selector('mat-option')

# Select the option by its text
visa_category_dropdown_option = page.wait_for_selector('mat-option:has-text("National Visa (stay of more than 90 days): Employment")')
visa_category_dropdown_option.click()

# # Select Subcategory
# subcategory_dropdown = page.locator("//div[@id='mat-select-value-5']")
# subcategory_dropdown.click()
# subcategory_option = page.locator(
# f"//mat-option[starts-with(@id,'mat-option-')]/span[contains(text(), '{appointment_params.visa_sub_category}')]"
# )
# subcategory_option.click()
visa_subcategory_dropdown = page.query_selector_all('mat-form-field')[2]

visa_subcategory_dropdown.click()

# Wait for the dropdown options to appear
page.wait_for_selector('mat-option')

# Select the option by its text
visa_subcategory_dropdown_option = page.wait_for_selector('mat-option:has-text("Employment: any other employment (also vocational training)")')
visa_subcategory_dropdown_option.click()
try:
appointment_date_element = page.wait_for_selector("div.alert")
print(appointment_date_element)
date_text = appointment_date_element.text_content()
print(appointment_date_element.text_content())
if (
len(date_text) != 0
):
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime("%Y-%m-%d %H:%M:%S")
return [f"message = {date_text} at {st}"]
except Exception as e:
print("Error '{0}' occured. Arguments {1}.".format(e.message, e.args))
return None