-1

I am using Python selenium chrome driver and i am stuck at filling out the csc and the year of the creditcard information field ( look at picture ). The credit card number and month works fine with this code:

        iframe = driver.find_element_by_xpath("//iframe[@class='js-iframe']")
        driver.switch_to.frame(iframe)
        inputCC = WebDriverWait(driver, 30).until(
            lambda driver: driver.find_element_by_id("encryptedCardNumber")
        )
        inputCC.send_keys("1111222233334444")
        driver.switch_to.default_content()

        time.sleep(1)
        iframe = driver.find_element_by_xpath("//iframe[@class='js-iframe']")
        driver.switch_to.frame(iframe)
        inputCC = WebDriverWait(driver, 30).until(
            lambda driver: driver.find_element_by_id("encryptedExpiryMonth")
        )
        inputCC.send_keys("08")
        driver.switch_to.default_content()

I tried to use the same for the csc and year with changing the id but it didnt work. How to do it?

Creditcard momth console insight Creditcard year console insight Creditcard csc console insight

YvesEsel
  • 29
  • 1
  • 6

1 Answers1

1

I don't run your code, but I checked the HTML & your code. Here's what I think:

Because //iframe[@class='js-iframe'] is a very general XPATH, you need to be more specific. In your site, you have many iframes with the same XPATH.

You can fill the Month because after calling iframe = driver.find_element_by_xpath("//iframe[@class='js-iframe']"), it gives you the FIRST iframe, which contains the Month.

Your code fails for Year/CSC because it uses the FIRST iframe (which contains Month) to locate Year & CSC.


To fix, you have 2 methods.

  1. Write the correct XPATH.
  • Month iframe: //span[@data-cse="encryptedExpiryMonth"]/iframe
  • Year iframe: //span[@data-cse="encryptedExpiryYear"]/iframe
  • CSC iframe: //span[@data-cse="encryptedSecurityCode"]/iframe
  1. Find a list of iframes
iframe_list = driver.find_elements_by_xpath("//iframe[@class='js-iframe']")
month_iframe = iframe_list[0]
year_iframe = iframe_list[1]
csc_iframe = iframe_list[2]
jackblk
  • 1,076
  • 8
  • 19