下拉列表和Selenium复选框(python3)

时间:2017-01-24 12:29:41

标签: python python-3.x selenium automated-tests selenium-chromedriver

我试图在adidas上自动填写注册,我不知道如何选择复选框,特别是DOB的下拉菜单:

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

这对于复选框不起作用:

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

我不知道如何完成DOB的下拉列表。

1 个答案:

答案 0 :(得分:1)

为了能够处理目标<fieldset>,您首先需要切换到相应的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"]'))

然后您可以处理所需的下拉列表:

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

点击复选框:

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