0

I have this python code which logins to gmail:

class GMAIL_LOGIN():


def __init__(self, driver):

    self.driver=driver
    self.sl=SeleniumExtended(self.driver)

def login_to_gmail(self, email, password):
    with SB(uc=True) as sb:
        sb.open("https://www.google.com/gmail/about/")
        sb.click('a[data-action="sign in"]')
        sb.type('input[type="email"]', email)
        sb.click('button:contains("Next")')
        sb.sleep(5)
        sb.type('input[type="password"]', password)
        sb.click('button:contains("Next")')



service = Service(executable_path=r"C:\Users\RoyMazin\Documents\BrowserDrivers\chromedriver.exe")

options = webdriver.ChromeOptions()


driver = webdriver.Chrome(service=service, options=options)


mr.login_to_gmail("example@gmail.com","Test1234!")


time.sleep(5)
pdb.set_trace()

however, after mr.login_to_gmail is executed the browser is closed immediatly. I want to execute other commands after this but am unable to.

Roy idiot
  • 21
  • 4

1 Answers1

0

Once your code exits the with block, the driver is closed. Put your breakpoint at the end of that like this:

def login_to_gmail(self, email, password):
    with SB(uc=True) as sb:
        sb.open("https://www.google.com/gmail/about/")
        sb.click('a[data-action="sign in"]')
        sb.type('input[type="email"]', email)
        sb.click('button:contains("Next")')
        sb.sleep(5)
        sb.type('input[type="password"]', password)
        sb.click('button:contains("Next")')
        import pdb; pdb.set_trace()

Then the breakpoint is activated when reaching the end. Type c and press Enter to continue.

Michael Mintz
  • 9,007
  • 6
  • 31
  • 48