GMail is blocking login via Automation (Selenium)

后端 未结 5 1975
你的背包
你的背包 2021-02-07 22:46

I am using selenium to automate a mail verification process in a web application. I have a script already in place to login to gmail and read an activation mail received on the

相关标签:
5条回答
  • 2021-02-07 23:02
    1. Add cookie editor to the browser.

    2. add your account cookie information to your browser. Your account will automatically open.

    0 讨论(0)
  • 2021-02-07 23:05

    I just tried something out that worked for me after several hours of trial and error.

    Adding args: ['--disable-web-security', '--user-data-dir', '--allow-running-insecure-content' ] to my config resolved the issue.

    I realized later that this was not what helped me out as I tried with a different email and it didn't work. After some observations, I figured something else out and this has been tried and tested.

    Using automation:

    Go to https://stackoverflow.com/users/login Select Log in with Google Strategy Enter Google username and password Login to Stackoverflow Go to https://gmail.com (or whatever Google app you want to access)

    After doing this consistently for like a whole day (about 24 hours), try automating your login directly to gmail (or whatever Google app you want to access) directly... I've had at least two other people do this with success. PS - You might want to continue with the stackoverflow login until you at least get a captcha request as we all went through that phase as well.

    0 讨论(0)
  • 2021-02-07 23:11

    After some trial and error, found out that this issue happens only in a scenario when multiple gmail accounts have already been created from the same App/IP/Device. Google somehow is marking those accounts and blocks them if they are launched by automation frameworks/extensions.

    Temporary Solutions:

    • Create a fresh GMail account using a different mobile number from another device (Not recommended).
    • We should be using workarounds like nodemailer zeolearn.com/magazine/sending-and-receiving-emails-using-nodejs (as mentioned by Rahul L as a suggestion)
    • Automate temporary mail providers like Guerilla Mail or 10 Minute Mail if you are worried about only receiving mails

    My humble opinion is to entirely avoid automating the UI of third party Mail applications as you cannot predict how their UI and elements will change. They might block you from launching for security purposes and they have every right to do so!

    0 讨论(0)
  • 2021-02-07 23:13

    Steps to login to gmail through stackoverflow :

    1. Open a browser window and open stackoverflow
    2. Click on log in
    3. Login with google
    4. Enter email and password
    5. Stackoverflow is logged in with gmail credentials
    6. Now open mail.google.com (gmail.com)
    7. You are now logged into gmail using selenium

    You can copy this code and paste in your editor, you have to enter the path of your chrome driver, email address and password for your gmail where it is asked in the code.

    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.common.by import By
    import time
    
    driver=webdriver.Chrome('Enter the path of the chrome driver here')
    driver.get("https://stackoverflow.com/")
    
    driver.maximize_window()
    
    time.sleep(5)
    
    driver.find_element(By.XPATH, '/html/body/header/div/ol[2]/li[2]/a[1]').click()#Log in button in stackoverflow
    time.sleep(5)
    
    driver.find_element(By.XPATH, '//*[@id="openid-buttons"]/button[1]').click()# Log in with Google button
    time.sleep(5)
    
    driver.find_element(By.XPATH, '//*[@id="identifierId"]').send_keys("Enter email address")# Enter email address
    
    time.sleep(5)
    
    driver.find_element(By.XPATH, '//*[@id="identifierNext"]/div/button/div[2]').click() # Click next button after entering email address
    time.sleep(5)
    
    driver.find_element(By.XPATH, '//*[@id="password"]/div[1]/div/div[1]/input').send_keys("Enter password")#Enter password
    
    time.sleep(5)
    
    driver.find_element(By.XPATH, '//*[@id="passwordNext"]/div/button/div[2]').click()# Click on next button after entering the password
    
    time.sleep(5)
    
    driver.get("https://mail.google.com")
    
    time.sleep(5)
    
    driver.close()
    
    0 讨论(0)
  • 2021-02-07 23:23

    You need to open your editor and copy this code and paste them and save with this name as email.py and then open your terminal/cmd/powershell in that directory and type this python .\email.py

    Note:

    Make sure your chrome driver in that directory where you save python file

    You need to copy this code and paste in your editor

    Here is that script:

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    import time
    import pyautogui as pg
    
    
    username = input("Enter Your Username: ")
    
    password = input("Enter Your Password: ")
    
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.get("https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1#identifier")
    driver.maximize_window()
    
    
    mail = WebDriverWait(driver, 100).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='identifierId']"))).send_keys(username)
    
    login = WebDriverWait(driver, 100).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='identifierNext']/span"))).click()
    
    passw = WebDriverWait(driver, 100).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='password']/div[1]/div/div[1]/input"))).send_keys(password)
    
    next = WebDriverWait(driver, 100).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='passwordNext']/span/span"))).click()
    
    0 讨论(0)
提交回复
热议问题