Trying to login to Gmail with Selenium but "This browser or app may not be secure"

  • After a lot of Google searching, I got my python script to login with Selenium, but now the page is telling me that:

    This browser or app may not be secure. Learn more
    Try using a different browser. If you’re already using a supported browser, you can refresh your screen and try again to sign in.

    Is there anyway around this? Here is my current script.

    from selenium import webdriver
    from import ChromeDriverManager
    from selenium.webdriver.common.action_chains import ActionChains
    from selenium.webdriver.common.keys import Keys
    driver = webdriver.Chrome(ChromeDriverManager().install())
    email = driver.find_element_by_id('identifierId')
    actions = ActionChains(driver)

    Sending keys directly to the password field wasn't working so I tried sending keys to the browser itself and now I'm getting this error. I don't know how to proceed further.

    Edit: Toggling Less secure app access did not work:

  • This Google Support page states that sign in via browsers that "Use automation testing frameworks" is being disabled for the following security reasons and Google advices to do "Sign in with Google" using browser-based OAuth 2.0 authentication service.

    As some websites, like allow you to sign in to their services using "Sign in with Google" it must happen via Google OAuth 2.0 authentication. This implicates that doing so you are also indirectly signing in to your Google account and therefore you can use all the Google services.

    So you can fully automatically sign in to your Google account, e.g. by using a Python script, by performing these actions in your code:

    1. Open a new browser window that is controlled by selenium webdriver
    2. In the same window load the StackOverflow login page (or any other site that uses "Sign in with Google")
    3. Choose for "Log in with Google"
    4. Provide your Google account credentials and login to StackOverflow
    5. Load the Google mailbox by opening or

    This way you land down in your Gmail mailbox without performing any manual actions.

    Please remember to add some 5s delays between different actions as doing it too quickly or too frequently can be recognized by StackOverflow as malicious automated actions and you can get blocked and you will need to make the manual I'm not a robot verification

Log in to reply

Suggested Topics