Matthew Casey
Matthew Casey

Reputation: 165

Dropdown and checkboxes with Selenium (python3)

Im trying to auto fill a registration on adidas and am not sure how to select checkboxes and especially dropdowns for DOB:

driver = webdriver.Chrome()
driver.get("https://www.adidas.co.uk/on/demandware.store/Sites-adidas-GB-Site/en_GB/MyAccount-Register")

This is whats not working for the checkbox:

driver.find_element_by_id('ffCheckbox').click()

I have no idea how to complete the dropdown for DOB.

Upvotes: 1

Views: 915

Answers (1)

Andersson
Andersson

Reputation: 52675

To be able to handle target <fieldset> you first need to switch to appropriate iframe:

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

driver.switch_to_frame(driver.find_element_by_xpath('//iframe[@class="sso-iframe"]'))

Then you can handle required drop-down like:

driver.find_element_by_xpath("//a[.='DD']").click() # Open drop-down
wait = WebDriverWait(driver, 10)
wait.until(EC.visibility_of_element_located((By.XPATH,'//span[@data-val="1"]'))).click() # select first day

To click on checkbox:

driver.find_element_by_xpath('.//span[@id="consentLabel"]').click() 

Upvotes: 1

Related Questions