Skip to content

Commit

Permalink
t`MINOR: added changes for selecting dropdown options
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravindra Chhetri committed Apr 24, 2024
1 parent 2e1aae3 commit 06156d4
Showing 1 changed file with 67 additions and 33 deletions.
100 changes: 67 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,72 @@ 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))

Check notice on line 172 in vfs_appointment_bot/vfs_bot/vfs_bot_de.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

vfs_appointment_bot/vfs_bot/vfs_bot_de.py#L172

Trailing whitespace
return None

0 comments on commit 06156d4

Please sign in to comment.