I've tried login with Gmail or any Google services but it shows the following "This browser or app may not be secure" message:
I also tried to do options like enable less secure app in my acc but it didn't work. then I made a new google account and it worked with me. but not with my old acc.
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
browser = webdriver.Chrome()
browser.get('https://accounts.google.com/servicelogin')
search_form = browser.find_element_by_id("identifierId")
search_form.send_keys('mygmail')
nextButton = browser.find_elements_by_xpath('//*[@id ="identifierNext"]')
search_form.send_keys('password')
nextButton[0].click()
While automating Captcha is not the best practice, there are three efficient ways of handling Captcha in Selenium: By disabling the Captcha in the testing environment. Adding a hook to click the Captcha checkbox. By adding a delay to the Webdriver and manually solve Captcha while testing.
We can automate the Gmail login process using Selenium webdriver in Java. To perform this task, first we have to launch the Gmail login page and locate the email, password and other elements with the findElement method and then perform actions on them.
Unable to sign into google with selenium automation because of "This browser or app may not be secure." Ask Question Asked2 years, 1 month ago Active7 months ago Viewed27k times 14 4 I am trying to login to google with selenium and I keep getting the error that "This browser or app may not be secure."
3 I've seen other places that when people allow less secure apps it doesnt secure the problem. I tried it myself and it didnt work. Even though I allow it on my own google account it doesnt transfer to the window selenium opens.
#2 is impossible. Selenium needs chromedriver in order to control the browser. First of all don't use chrome and chromedriver. You need to use Firefox. (if not installed) Download and install Firefox. Login to Google with normal Firefox. You need to show the Google site that you are not a robot. You can use code like this:
Selenium test scripts to login into google account through new ajax login form Additional Considerations Finally, some old browser versions might not be supported, so ensure that: JDKis upgraded to current levels JDK 8u241. Seleniumis upgraded to current levels Version 3.141.59. ChromeDriveris updated to current ChromeDriver v80.0level.
This is working for me. I found the solution from GitHub.
from selenium import webdriver
from selenium_stealth import stealth
options = webdriver.ChromeOptions()
options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
options.add_argument('--disable-blink-features=AutomationControlled')
driver = webdriver.Chrome(options=options)
stealth(driver,
languages=["en-US", "en"],
vendor="Google Inc.",
platform="Win32",
webgl_vendor="Intel Inc.",
renderer="Intel Iris OpenGL Engine",
fix_hairline=True,
)
driver.get("https://www.google.com")
First of all don't use chrome and chromedriver. You need to use Firefox.(if not installed) Download and install Firefox. Login to Google with normal Firefox.
You need to show the Google site that you are not a robot. You can use code like this:
from selenium import webdriver
import geckodriver_autoinstaller
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
geckodriver_autoinstaller.install()
profile = webdriver.FirefoxProfile(
'/Users/<user name>/Library/Application Support/Firefox/Profiles/xxxxx.default-release')
profile.set_preference("dom.webdriver.enabled", False)
profile.set_preference('useAutomationExtension', False)
profile.update_preferences()
desired = DesiredCapabilities.FIREFOX
driver = webdriver.Firefox(firefox_profile=profile,
desired_capabilities=desired)
This can help you find your profile location.
Actually there is only one reason, chromedriver was coded by Google. They can easily understand if it is a bot or not. But when we add user data with Firefox, they cannot understand if there is a bot or not.
You can fool Google like this. It worked for me too. I tried very hard to do this. Hope it will be resolved in you too.
You can easily bypass the google bot detection with the undetected_chromedriver
:
pip install undetected-chromedriver
pip install selenium
Credits: https://github.com/xtekky/google-login-bypass/blob/main/login.py
import undetected_chromedriver as uc
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
class Main:
def __init_(self) -> None:
self.url = 'https://accounts.google.com/ServiceLogin'
self.driver = driver = uc.Chrome(use_subprocess=True)
self.time = 10
def login(self, email, password):
WebDriverWait(self.driver, 20).until(EC.visibility_of_element_located((By.NAME, 'identifier'))).send_keys(f'{email}\n)
WebDriverWait(self.driver, 20).until(EC.visibility_of_element_located((By.NAME, 'password'))).send_keys(f'{password}\n)
self.code()
def code(self):
# [ ---------- paste your code here ---------- ]
time.sleep(self.time)
if __name__ == "__main__":
# ---------- EDIT ----------
email = 'email' # replace email
password = 'password' # replace password
# ---------- EDIT ----------
driver = Main()
driver.login(email, password)
From terminal pip install undetected-chromedriver
then do the following steps, as shown below.
NOTE: indent your code inside if name == main, as i have done, only then the program will work
import undetected_chromedriver as uc
from time import sleep
from selenium.webdriver.common.by import By
if __name__ == '__main__':
driver = uc.Chrome()
driver.get('https://accounts.google.com/')
# add email
driver.find_element(By.XPATH, '//*[@id="identifierId"]').send_keys(YOUR EMAIL)
driver.find_element(By.XPATH, '//*[@id="identifierNext"]/div/button/span').click()
sleep(3)
driver.find_element(By.XPATH, '//*[@id="password"]/div[1]/div/div[1]/input').send_keys(YOUR PASSWORD)
driver.find_element(By.XPATH, '//*[@id="passwordNext"]/div/button/span').click()
sleep(10)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With