@@ -236,19 +236,35 @@ def fill_and_save_cc_panel_information(
236
236
credit_card_fill_information: The object containing all the sample data
237
237
"""
238
238
fields = {
239
- "card_number " : credit_card_fill_information .card_number ,
240
- "expiration_month " : credit_card_fill_information .expiration_month ,
241
- "expiration_year " : f"20{ credit_card_fill_information .expiration_year } " ,
242
- "name" : credit_card_fill_information .name ,
239
+ "cc-number " : credit_card_fill_information .card_number ,
240
+ "cc-exp-month " : int ( credit_card_fill_information .expiration_month ) ,
241
+ "cc-exp-year " : f"20{ credit_card_fill_information .expiration_year } " ,
242
+ "cc- name" : credit_card_fill_information .name ,
243
243
}
244
244
245
- for field in fields :
246
- self .actions .send_keys (fields [field ] + Keys .TAB ).perform ()
245
+ # for field in fields:
246
+ # self.actions.send_keys(fields[field] + Keys.TAB).perform()
247
+ #
248
+ # # Press tab again to navigate to the next field (this accounts for the second tab after the name field)
249
+ # self.actions.send_keys(Keys.TAB).perform()
250
+ # # Finally, press enter
251
+ # self.actions.send_keys(Keys.ENTER).perform()
247
252
248
- # Press tab again to navigate to the next field (this accounts for the second tab after the name field)
249
- self .actions .send_keys (Keys .TAB ).perform ()
250
- # Finally, press enter
251
- self .actions .send_keys (Keys .ENTER ).perform ()
253
+ form_element = self .get_element ("form-container" )
254
+ children = [
255
+ x .get_attribute ("id" )
256
+ for x in form_element .find_elements (By .CSS_SELECTOR , "*" )
257
+ ]
258
+
259
+ for key , val in fields .items ():
260
+ if key in children :
261
+ form_field = form_element .find_element (By .ID , key )
262
+ if form_field .tag_name == "select" :
263
+ self .set_select_field (key , val )
264
+ else :
265
+ form_field .send_keys (val )
266
+ self .get_element ("save-button" ).click ()
267
+ return self
252
268
253
269
def add_entry_to_saved_payments (self , cc_data : CreditCardBase ):
254
270
"""
@@ -259,7 +275,7 @@ def add_entry_to_saved_payments(self, cc_data: CreditCardBase):
259
275
Arguments:
260
276
cc_data: The object containing all the sample data
261
277
"""
262
- self .switch_to_saved_payments_popup_iframe ()
278
+ self .switch_to_edit_saved_payments_popup_iframe ()
263
279
self .fill_and_save_cc_panel_information (cc_data )
264
280
self .switch_to_default_frame ()
265
281
self .close_dialog_box ()
@@ -458,10 +474,18 @@ def get_password_exceptions_popup_iframe(self) -> WebElement:
458
474
return iframe
459
475
460
476
# Data Extraction and Processing
461
- def set_country_autofill_panel (self , country : str ) -> BasePage :
462
- """Sets the country value in the autofill view"""
463
- select_country = Select (self .driver .find_element (By .ID , "country" ))
464
- select_country .select_by_value (country )
477
+ def set_select_field (self , field_selector : str , value : str | int ) -> BasePage :
478
+ """Sets the select field to the correct value."""
479
+ select_element = Select (self .driver .find_element (By .ID , field_selector ))
480
+ if field_selector == "cc-exp-month" or field_selector == "cc-exp-year" :
481
+ if field_selector == "cc-exp-year" :
482
+ available_options = [
483
+ x .get_attribute ("value" ) for x in select_element .options
484
+ ]
485
+ value = available_options .index (value )
486
+ select_element .select_by_index (value )
487
+ else :
488
+ select_element .select_by_value (value )
465
489
return self
466
490
467
491
def fill_and_save_address_panel_information (
@@ -485,7 +509,7 @@ def fill_and_save_address_panel_information(
485
509
"email" : address_data .email ,
486
510
}
487
511
488
- self .set_country_autofill_panel ( address_data .country_code )
512
+ self .set_select_field ( "country" , address_data .country_code )
489
513
form_element = self .get_element ("form-container" )
490
514
children = [
491
515
x .get_attribute ("id" )
0 commit comments