How do you automate an OTP using python selenium?



  • I have a scenario where I need to perform a login, but the problem is its based on OPT (I mean once I enter a phone number to that number I receive an OTP That OTP is the password)



  • In software testing companies generally we are automating it by storing OTP in Database and then it is easy to automate by us while devops testing. You can use sql connection and get the 'OTP' code.

    Please find below code snippet in support of above suggestion. I hope this approach will work well for you.

    import pyodbc 
    cnxn = pyodbc.connect("Driver={SQL Server Native Client 11.0};"
                          "Server=server_name;"
                          "Database=db_name;"
                          "Trusted_Connection=yes;")
    
    
    cursor = cnxn.cursor()
    cursor.execute('SELECT otp FROM Table')
    
    for row in cursor:
        print('row = %r' % (row,)) 
    

    Thanks.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2