david
david

Reputation: 6785

How to select this text field with Selenium webdriver?

How do I select the credit card number field for a selenium webdriver test?

https://secure-store.nike.com/us/checkout/html/billing.jsp?_requestid=173323

cc = driver.find_element_by_id("creditCardNumber")

I get an unable to locate element error on this line and I have no idea why.

# click next button
driver.find_element_by_id("shippingSubmit").click()

# enter credit card number
cc = driver.find_element_by_id("creditCardNumber")
cc.click()
cc.clear()
cc.send_keys("4411111111111111")

# enter expiration
selectmonth = Select(driver.find_element_by_id("expirationMonth"))
selectmonth.select_by_value("10")

# enter expiration year
selectyear = Select(driver.find_element_by_id("expirationYear"))
selectyear.select_by_value("2012")

Upvotes: 1

Views: 1725

Answers (1)

alecxe
alecxe

Reputation: 473803

The payment form is wrapped inside an iframe element. Switch to it before locating the element:

wait = WebDriverWait(driver, 10)
driver.switch_to.frame("billingFormFrame") 

cc = wait.until(EC.element_to_be_clickable((By.ID, "creditCardNumber"))
cc.click()
# ...

Upvotes: 1

Related Questions