Filling Out Credit Card IFrame

Viewed 47

Trying to buy 2 security cameras from Ubiquiti. I cannot, for the life of me, figure out how to navigate to the iframe. I've been trying to do this for probably 4-5 hours total now.

Right now, I have this: (wd is webdriver, chrome)

wd.switch_to.frame(wd.find_element("title", 'card-fields-iframe'))

credit_card_number = wd.find_element("xpath" , '//*[@id="number"]')

type(credit_card_number)

credit_card_number.send_keys("1234123412341234")

I can't use an ID to hit the iframe because it changes every time you access the page, as does the name. The only constant I've seen is title but idk if that works. Any help would be apprecaited.

enter image description here

2 Answers

There are 4 elements in 'Credit Card' section. Each element is within a separate iframe.

I tried with the below code, it is working. In Card Number and Expiration Date fields, send_keys is not working properly, so I used javascript executor.

# Card number
driver.switch_to.frame(driver.find_element(By.XPATH,".//*[starts-with(@id,'card-fields-number-')]"))
time.sleep(0.5)
card_number = driver.find_element(By.XPATH,".//*[@id='number']")
card_number.click()
driver.execute_script("arguments[0].value='1234 5678 9101 1121';", card_number)
time.sleep(0.5)

driver.switch_to.default_content()
time.sleep(0.5)

# Name on card
driver.switch_to.frame(driver.find_element(By.XPATH,".//*[starts-with(@id,'card-fields-name-')]"))
time.sleep(0.5)
driver.find_element(By.XPATH, ".//*[@id='name']").send_keys("TestName")

driver.switch_to.default_content()
time.sleep(0.5)

# Expiration date
driver.switch_to.frame(driver.find_element(By.XPATH,".//*[starts-with(@id,'card-fields-expiry-')]"))
time.sleep(0.5)
card_expiry_date = driver.find_element(By.XPATH,".//*[@id='expiry']")
card_expiry_date.click()
driver.execute_script("arguments[0].value='12/2026';", card_expiry_date)

driver.switch_to.default_content()
time.sleep(0.5)

# Security code
driver.switch_to.frame(driver.find_element(By.XPATH,".//*[starts-with(@id,'card-fields-verification_value-')]"))
time.sleep(0.5)
driver.find_element(By.XPATH, ".//*[@id='verification_value']").send_keys("123")

driver.switch_to.default_content()

driver.execute_script("window.scrollTo(0, document.body.scrollHeight)")
time.sleep(2)
driver.find_element(By.XPATH, "(.//*[text()='Pay now']//parent::button)[1]").click()

@Roo try the following:

instead of:

wd.switch_to.frame(wd.find_element("title", 'card-fields-iframe'))

try:

wd.switch_to.frame(wd.find_element(By.CLASS_NAME, 'card-fields-iframe'))

You will need to import the following:

from selenium.webdriver.common.by import By

Seems from your screenshot, the class name of iframe element is 'card-fields-iframe' and not title.

Related