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
Add cookie editor to the browser.
add your account cookie information to your browser. Your account will automatically open.
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.
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:
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!
Steps to login to gmail through stackoverflow :
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()
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<mpl=default<mplcache=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()