0

How to switch back from iFrame index to the relative parent in (Python)? I use this code but not working for me :

def type_order_credit_card1_number(self, credit_card_1_number):
    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, self.order_credit_card_number_text_id))).send_keys(credit_card_1_number)

    time.sleep(4)

def type_order_credit_card_expiry_date(self, credit_card_1_expiry_date):
    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, self.order_credit_card_expiry_date_text_id))).send_keys(
        credit_card_1_expiry_date)

I want to switch from [selectFrame index=2] to [selectFrame relative=parent] to type credit card expiry date and cvv (the card number works fine)

General Grievance
  • 4,259
  • 21
  • 28
  • 43
FlutterLover
  • 325
  • 6
  • 17

2 Answers2

0

To switch back from child <iframe> to the immediate parent <iframe> you need to use the switch_to() statement as follows:

driver.switch_to.parent_frame()

To switch back from any of the child or grand child <iframe> to the Top Most level i.e. the default content you need to use:

driver.switch_to.default_content()

Reference

You can find a couple of relevant discussions in:

undetected Selenium
  • 151,581
  • 34
  • 225
  • 281
0

I have chage my code by using TAB to type number but always it type one number for the second tab (to type cvv number) it type just 7 not 737!

WebDriverWait(self.driver, 80).until(
         EC.element_to_be_clickable((By.XPATH, self.order_credit_card_number_text_id))).send_keys(Keys.TAB,'1223', Keys.TAB, '737')
    time.sleep(4)
FlutterLover
  • 325
  • 6
  • 17