0

I've been trying to log into my google account using selenium but once I pass in the email and hit enter it redirects to the following message

"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."

Here is my python code:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
options = webdriver.ChromeOptions()
options.add_argument("--enable-javascript")
driver = webdriver.Chrome(executable_path='path/to/chrome/driver',chrome_options = options)
url = "https://accounts.google.com/signin"

driver.get(url)
username = 'email'
password = 'password'

email_phone = driver.find_element_by_id('identifierId')
email_phone.send_keys(username)
email_phone.send_keys(Keys.RETURN)
email_phone = driver.find_element_by_id('password')
email_phone.send_keys(password)
email_phone.send_keys(Keys.RETURN)

please note that I'm new to python and selenium. I would very much appreciate your help. Thank you in advance

I have tried to use the methods described in Selenium Google Login Block but it still gave me the same message

ap123
  • 21
  • 3

1 Answers1

0

Selenium can already do this (by exploiting a bypass).

By default, Google detects and effectively blocks all logins from Selenium webdriver.

The following link comes from the Google OAuth Playground, ensuring the practicality of the link. It most likely won't expire any time soon.

https://accounts.google.com/o/oauth2/v2/auth/oauthchooseaccount?redirect_uri=https%3A%2F%2Fdevelopers.google.com%2Foauthplayground&prompt=consent&response_type=code&client_id=407408718192.apps.googleusercontent.com&scope=email&access_type=offline&flowName=GeneralOAuthFlow

You can use that link (ie. driver.get()) to log into your Google account.

This bypasses the automation checks allows you to log into Google using Selenium. At least for now.

UPDATE: As of January 2021, this no longer works.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
idontknow
  • 438
  • 5
  • 16