Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

“This browser or app may not be secure” error while attempting to login in to Gmail account using GeckoDriver Firefox through Selenium and Python

I want to login to my gmail account using selenium. I use python2.7 . It doesn't have error, but the page said that I couldn't sign in to my account because some reason. you can see the screenshot below. screenshot

it is my code:

import time
import selenium
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

EXE_PATH = r'C:\Users\LENOVO\Downloads\geckodriver.exe'
driver = webdriver.Firefox(executable_path=EXE_PATH)

def login():
    mail = 'myMail'
    pw = 'myPassword'
    driver.get('https://gmail.com')
    email = driver.find_element_by_name('identifier')
    email.send_keys(mail)
    driver.find_element_by_id('identifierNext').click()
    time.sleep(10)
    password = driver.find_element_by_name('password')
    password.send_keys(pw)
    driver.find_element_by_id('passwordNext').click()

what have to I do? please help me, I just a noob and beginner. thanks master

like image 374
Ardo Rianda Avatar asked Dec 28 '19 22:12

Ardo Rianda


1 Answers

First install undetected-chromedriver using pip. It's a library which bypass Chrome security and allow you to proceed further.

pip install undetected-chromedriver

Then instead of creating using chromedriver.exe like driver = webdriver.Chrome(r"chromedriver.exe"), use the Chrome() function from the library you just installed.

Full Code Example in Python:

import undetected_chromedriver.v2 as uc
from time import sleep

username = '[email protected]'
password ='password'

driver = uc.Chrome()

driver.delete_all_cookies()

driver.get('https://accounts.google.com/ServiceLogin')
sleep(2)

driver.find_element_by_xpath('//input[@type="email"]').send_keys(username)
driver.find_element_by_xpath('//*[@id="identifierNext"]').click()
sleep(2)

driver.find_element_by_xpath('//input[@type="password"]').send_keys(password)
driver.find_element_by_xpath('//*[@id="passwordNext"]').click()
sleep(2)

driver.get('https://gmail.com')
sleep(2)
like image 87
Rajan Gautam Avatar answered Oct 13 '22 19:10

Rajan Gautam