I want to select the date of birth from the following drop down menu using Python's Selenium.
Image of drop down menu (Sorry, I'm new to this page and can't upload images directly)
Page: https://www.seitensprungmarkt.com/#b (FSK 18) You must submit further into the page to get to it.
However, I'm not able to select it without using XPATH
. I want to loop through it.
I could use driver.find_element(By.XPATH, '//*[@id="step5"]/div[1]/div/div[2]/div[1]/div/div[2]/div/select'
but like I said I want to loop through it and therefore need to find it with CSS_SELECTOR
I guess.
THANKS FOR HELPING ME OUT!! :) <3
I tried:
form = driver.find_element(By.CSS_SELECTOR, 'select')
# Also .find_elements
Select(form[0]).select_by_index('2')
# Also .select_by_value
# and
form = driver.find_element(By.CLASS_NAME, 'form-control')
# Also .find_elements
Select(form[0]).select_by_index('2')
# Also .select_by_value
HTML:
<div >
<select name="dob_day" >
<option value="1">1</option>
...
<div >
<select name="dob_month" >
<option value="1">Januar</option>
...
<div >
<select name="dob_year" >
<option value="2004">2004</option>
...
<div >
<select name="relationship_status" >
<option value="single">Single</option>
...
CodePudding user response:
The solution was to add a .
before form-control
because it's a class.
form = driver.find_elements(By.CSS_SELECTOR, '.form-control')