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