K
K
kolomiec_artiom2020-01-07 21:42:18
Python
kolomiec_artiom, 2020-01-07 21:42:18

How to click on dropdown menu in selenium?

Good evening! I need to select a specific position in a drop down menu using selenium python. How to do it?
To be specific: there is a site - https://zhenyanovokshanov1.wixsite.com/klinika/boo... (this is my site, which I specially created for testing). You need to choose a specific doctor in it. How to do it?
I hope for your help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Yakushenko, 2020-01-07
@kolomiec_artiom

Because all the content on the page is loaded by JS into the frame, you need to switch to it in order to work with the data that is in it:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

target_name = 'Иванов И.И.'

driver = webdriver.Chrome()
driver.get(
    'https://zhenyanovokshanov1.wixsite.com/klinika/bookings-checkout/%D0%BE%D1%84%D1%82%D0%B0%D0%BB%D1%8C%D0%BC%D0%BE%D0%BB%D0%BE%D0%B3/book'
)
driver.switch_to.frame(driver.find_element_by_xpath('.//iframe'))
dropdown_menu = WebDriverWait(driver, 30).until(EC.visibility_of_element_located((
    By.XPATH, './/span[@data-hook="dropdown-select-label"]'
)))
dropdown_menu.click()
target_elem = WebDriverWait(driver, 30).until(EC.visibility_of_element_located((
    By.XPATH, f'.//li[contains(text(), "{target_name}")]'
)))
target_elem.click()

You can return to the root frame withdriver.switch_to.default_content()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question