pythonseleniumkatalon-recorder

Enable to switch between iframe=1 and relative=parent in Python


How to switch between iFrame and parent frame to complete a payment with a credit card : I use driver.switch_to.parent_frame() and driver.switch_to.default_content() but not working, i can just type the card number. In Katalon i have : selectFrame | index=4 | and selectFrame | relative=parent |

    def type_order_credit_card1_number(self):
    WebDriverWait(self.driver, 80).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, '//iframe[1]')))
    WebDriverWait(self.driver, 80).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='encryptedCardNumber']"))).send_keys('4444111111111111')
    time.sleep(2)
    self.driver.switch_to.parent_frame()
    WebDriverWait(self.driver, 80).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, '//iframe[2]')))
    WebDriverWait(self.driver, 80).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='encryptedExpiryDate']"))).send_keys('3023')
    time.sleep(2)
    self.driver.switch_to.parent_frame()
    WebDriverWait(self.driver, 80).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, '//iframe[3]')))
    WebDriverWait(self.driver, 80).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='encryptedSecurityCode']"))).send_keys('123')
    time.sleep(2)

this is the HTML :

<fieldset class="dkt-card dkt-card--verso"><div id="adyen-card-container"><div class="adyen-checkout__card-input _2EwzPPlqMjp7S2qHs4d9Dj"><div style="position: relative;"><div class="_1vuLtj7ctJkcDQcTmyZLaZ"><div class="adyen-checkout__spinner__wrapper "><div class="adyen-checkout__spinner adyen-checkout__spinner--large"></div></div></div><div class="adyen-checkout__card-input__form _3jXHyitM6npsG088lgDkjo"><div class="adyen-checkout__card__form"><div class="adyen-checkout__field adyen-checkout__field--cardNumber"><label class="adyen-checkout__label"><span class="adyen-checkout__label__text">Numéro de la carte</span><span class="adyen-checkout__input-wrapper"><span data-cse="encryptedCardNumber" class="adyen-checkout__input adyen-checkout__input--large adyen-checkout__card__cardNumber__input sMjS8HCbKiP5yR9Td9ZgQ"><img class="_1rgeOw_0KD58dhkU_NSVLF adyen-checkout__card__cardNumber__brandIcon" alt="card" src="https://checkoutshopper-test.adyen.com/checkoutshopper/images/logos/nocard.svg"><iframe src="https://checkoutshopper-test.adyen.com/checkoutshopper/securedfields/pub.v2.8215938043841895.aHR0cHM6Ly9iZXRhLmRlY2F0aGxvbi5jYQ.FgN_u5EF_RzoIGG26jTm0xfmIMbjB1MyAdkVdKd783w/3.0.0/securedFields.html?type=card" class="js-iframe" title="Iframe for secured card data input field" frameborder="0" scrolling="no" allowtransparency="true" style="border: none; height:100%; width:100%;"><p>Your browser does not support iframes.</p></iframe></span></span></label></div><div class="adyen-checkout__card__exp-cvc adyen-checkout__field-wrapper"><div class="adyen-checkout__field adyen-checkout__field--50 adyen-checkout__field--expiryDate"><label class="adyen-checkout__label"><span class="adyen-checkout__label__text">Date d'expiration</span><span class="adyen-checkout__input-wrapper"><span data-cse="encryptedExpiryDate" class="adyen-checkout__input adyen-checkout__input--small adyen-checkout__card__exp-date__input sMjS8HCbKiP5yR9Td9ZgQ"><iframe src="https://checkoutshopper-test.adyen.com/checkoutshopper/securedfields/pub.v2.8215938043841895.aHR0cHM6Ly9iZXRhLmRlY2F0aGxvbi5jYQ.FgN_u5EF_RzoIGG26jTm0xfmIMbjB1MyAdkVdKd783w/3.0.0/securedFields.html?type=card" class="js-iframe" title="Iframe for secured card data input field" frameborder="0" scrolling="no" allowtransparency="true" style="border: none; height:100%; width:100%;"><p>Your browser does not support iframes.</p></iframe></span></span></label></div><div class="adyen-checkout__field adyen-checkout__field--50 adyen-checkout__field__cvc adyen-checkout__field--securityCode"><label class="adyen-checkout__label"><span class="adyen-checkout__label__text">CVC / CVV</span><span class="adyen-checkout__input-wrapper"><span class="adyen-checkout__input adyen-checkout__input--small adyen-checkout__card__cvc__input sMjS8HCbKiP5yR9Td9ZgQ" data-cse="encryptedSecurityCode"><iframe src="https://checkoutshopper-test.adyen.com/checkoutshopper/securedfields/pub.v2.8215938043841895.aHR0cHM6Ly9iZXRhLmRlY2F0aGxvbi5jYQ.FgN_u5EF_RzoIGG26jTm0xfmIMbjB1MyAdkVdKd783w/3.0.0/securedFields.html?type=card" class="js-iframe" title="Iframe for secured card data input field" frameborder="0" scrolling="no" allowtransparency="true" style="border: none; height:100%; width:100%;"><p>Your browser does not support iframes.</p></iframe></span></span></label></div></div></div></div></div></div></div></fieldset>

Solution

  • Finaly i have found the solution, this is the code :

        def type_order_credit_card1_information(self):
        # Enter the credit card number
        IwebElement_Element = self.driver.find_element_by_xpath('//iframe[1]')
        self.driver.switch_to.frame(IwebElement_Element)
        test = WebDriverWait(self.driver, 20).until(
            EC.element_to_be_clickable((By.XPATH, "//input[@id='encryptedCardNumber']")))
        test.send_keys(credit_card1_number)
        self.driver.switch_to.parent_frame() # To switch to the parent frame
        # Enter the credit card expiry date
        IwebElement_Element2 = self.driver.find_element_by_xpath('//*[@id="adyen-card-container"]/div/div/div[2]/div/div[2]/div[1]/label/span[2]/span/iframe')
        self.driver.switch_to.frame(IwebElement_Element2)
        test = WebDriverWait(self.driver, 20).until(
            EC.element_to_be_clickable((By.XPATH, "//input[@id='encryptedExpiryDate']")))
        test.send_keys(credit_card1_expiry_date)
        self.driver.switch_to.parent_frame()  # To switch to the parent frame
        # Enter the credit card cvv security number
        IwebElement_Element3 = self.driver.find_element_by_xpath(
            '//*[@id="adyen-card-container"]/div/div/div[2]/div/div[2]/div[2]/label/span[2]/span/iframe')
        self.driver.switch_to.frame(IwebElement_Element3)
        test = WebDriverWait(self.driver, 20).until(
            EC.element_to_be_clickable((By.XPATH, "//input[@id='encryptedSecurityCode']")))
        test.send_keys(credit_card1_cvv_number)
        self.driver.switch_to.parent_frame()  # To switch to the parent frame