@@ -5278,9 +5278,10 @@ def is_chromedriver_too_old(self):
5278
5278
return True # chromedriver is too old! Please upgrade!
5279
5279
return False
5280
5280
5281
- def get_totp_code (self , totp_key = None ):
5282
- """Returns a time-based one-time password based on the
5283
- Google Authenticator algorithm. Works with Authy and Okta.
5281
+ def get_mfa_code (self , totp_key = None ):
5282
+ """Same as get_totp_code() and get_google_auth_password().
5283
+ Returns a time-based one-time password based on the
5284
+ Google Authenticator algorithm for multi-factor authentication.
5284
5285
If the "totp_key" is not specified, this method defaults
5285
5286
to using the one provided in [seleniumbase/config/settings.py].
5286
5287
Google Authenticator codes expire & change at 30-sec intervals.
@@ -5307,6 +5308,36 @@ def get_totp_code(self, totp_key=None):
5307
5308
totp = pyotp .TOTP (totp_key )
5308
5309
return str (totp .now ())
5309
5310
5311
+ def enter_mfa_code (
5312
+ self , selector , totp_key = None , by = By .CSS_SELECTOR , timeout = None
5313
+ ):
5314
+ """Enters into the field a Multi-Factor Authentication TOTP Code.
5315
+ If the "totp_key" is not specified, this method defaults
5316
+ to using the one provided in [seleniumbase/config/settings.py].
5317
+ The TOTP code is generated by the Google Authenticator Algorithm.
5318
+ This method will automatically press ENTER after typing the code."""
5319
+ self .__check_scope ()
5320
+ if not timeout :
5321
+ timeout = settings .SMALL_TIMEOUT
5322
+ self .wait_for_element_visible (selector , by = by , timeout = timeout )
5323
+ if self .recorder_mode :
5324
+ css_selector = self .convert_to_css_selector (selector , by = by )
5325
+ url = self .get_current_url ()
5326
+ if url and len (url ) > 0 :
5327
+ if ("http:" ) in url or ("https:" ) in url or ("file:" ) in url :
5328
+ origin = self .get_origin ()
5329
+ if self .get_session_storage_item ("pause_recorder" ) == "no" :
5330
+ time_stamp = self .execute_script ("return Date.now();" )
5331
+ sel_key = [css_selector , totp_key ]
5332
+ action = ["e_mfa" , sel_key , origin , time_stamp ]
5333
+ self .__extra_actions .append (action )
5334
+ # Sometimes Sign-In leaves the origin... Save work first.
5335
+ self .__origins_to_save .append (origin )
5336
+ tab_actions = self .__get_recorded_actions_on_active_tab ()
5337
+ self .__actions_to_save .append (tab_actions )
5338
+ mfa_code = self .get_mfa_code (totp_key )
5339
+ self .update_text (selector , mfa_code + "\n " , by = by , timeout = timeout )
5340
+
5310
5341
def convert_css_to_xpath (self , css ):
5311
5342
return css_to_xpath .convert_css_to_xpath (css )
5312
5343
@@ -6247,12 +6278,24 @@ def assert_element_not_present(
6247
6278
return True
6248
6279
6249
6280
def get_google_auth_password (self , totp_key = None ):
6250
- """ Same as self.get_totp_code () """
6251
- return self .get_totp_code (totp_key = totp_key )
6281
+ """ Same as self.get_mfa_code () """
6282
+ return self .get_mfa_code (totp_key = totp_key )
6252
6283
6253
6284
def get_google_auth_code (self , totp_key = None ):
6254
- """ Same as self.get_totp_code() """
6255
- return self .get_totp_code (totp_key = totp_key )
6285
+ """ Same as self.get_mfa_code() """
6286
+ return self .get_mfa_code (totp_key = totp_key )
6287
+
6288
+ def get_totp_code (self , totp_key = None ):
6289
+ """ Same as self.get_mfa_code() """
6290
+ return self .get_mfa_code (totp_key = totp_key )
6291
+
6292
+ def enter_totp_code (
6293
+ self , selector , totp_key = None , by = By .CSS_SELECTOR , timeout = None
6294
+ ):
6295
+ """ Same as self.enter_mfa_code() """
6296
+ return self .enter_mfa_code (
6297
+ selector = selector , totp_key = totp_key , by = by , timeout = timeout
6298
+ )
6256
6299
6257
6300
def assert_no_broken_links (self , multithreaded = True ):
6258
6301
""" Same as self.assert_no_404_errors() """
0 commit comments