Selenium Google Login Block

43,817

Solution 1

This error message...

This browser or app may not be secure

...implies that the WebDriver instance was unable to authenticate the Browsing Context i.e. Browser session.


This browser or app may not be secure

This error can happen due to different factors as follows:


Solution

In these cases the respective solution would be to:

You can find a detailed discussion in Unable to sign into google with selenium automation because of "This browser or app may not be secure."


Deep Dive

However, to help protect your account, Web Browsers may not let you sign in from some browsers. Google might stop sign-ins from browsers that:

  • Doesn't support JavaScript or have Javascript turned off.
  • Have AutomationExtension or unsecure or unsupported extensions added.
  • Use automation testing frameworks.
  • Are embedded in a different application.

Solution

In these cases there are diverse solutions:

  • Use a browser that supports JavaScript:

  • Chrome

  • Safari

  • Firefox

  • Opera

  • Internet Explorer

  • Edge

  • Turn on JavaScript in Web Browsers: If you’re using a supported browser and still can’t sign in, you might need to turn on JavaScript.

  • If you still can’t sign in, it might be because you have AutomationExtension / unsecure / unsupported extensions turned on and you may need to turn off as follows:

      public class browserAppDemo 
      {
          public static void main(String[] args) throws Exception 
          {
              System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
              ChromeOptions options = new ChromeOptions();
              options.addArguments("start-maximized");
              options.setExperimentalOption("useAutomationExtension", false);
              options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
              WebDriver driver =  new ChromeDriver(options); 
              driver.get("https://accounts.google.com/signin")
              new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='identifierId']"))).sendKeys("gashu");
              driver.findElement(By.id("identifierNext")).click();
              new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@name='password']"))).sendKeys("gashu");
              driver.findElement(By.id("passwordNext")).click();
              System.out.println(driver.getTitle());
          }
      }
    
  • You can find a couple of relevant discussions in:

  • Gmail login using selenium webdriver in java

  • 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:

Solution 2

I had the same problem and found the solution for it. I am using

1) Windows 10 Pro

2) Chrome Version 83.0.4103.97 (Official Build) (64-bit)

3) selenium ChromeDriver 83.0.4103.39

Some simple C# code which open google pages

var options = new ChromeOptions();
options.addArguments(@"user-data-dir=c:\Users\{username}\AppData\Local\Google\Chrome\User Data\");
IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver();
driver = new ChromeDriver(Directory.GetCurrentDirectory(), options);
driver.Url = "https://accounts.google.com/";
Console.ReadKey();

The core problem here you cant login when you use selenium driver, but you can use the profile which already logged to the google accounts.

You have to find where your Chrome store profile is and append it with "user-data-dir" option.

PS. Replace {username} with your real account name.

On linux the user profile is in "~/.config/google-chrome".

Solution 3

One Solution that works for me: https://stackoverflow.com/a/60328992/12939291 or https://www.youtube.com/watch?v=HkgDRRWrZKg

Short: Stackoverflow Login with Google Account with Redirect

from selenium import webdriver
from time import sleep

class Google:

    def __init__(self, username, password):

        self.driver = webdriver.Chrome('./chromedriver')
        self.driver.get('https://stackoverflow.com/users/signup?ssrc=head&returnurl=%2fusers%2fstory%2fcurrent%27')
        sleep(3)
        self.driver.find_element_by_xpath('//*[@id="openid-buttons"]/button[1]').click()
        self.driver.find_element_by_xpath('//input[@type="email"]').send_keys(username)
        self.driver.find_element_by_xpath('//*[@id="identifierNext"]').click()
        sleep(3)
        self.driver.find_element_by_xpath('//input[@type="password"]').send_keys(password)
        self.driver.find_element_by_xpath('//*[@id="passwordNext"]').click()
        sleep(2)
        self.driver.get('https://youtube.com')
        sleep(5)

username = ''
passwort = ''
Google(username, password)

Solution 4

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.

Solution 5

This might be still open / not answered

Here is an working (28.04.2021) example in this following thread: https://stackoverflow.com/a/66308429/15784196

Use Firefox as driver. I tested his example and it did work!

Share:
43,817
Ahmet Aziz Beşli
Author by

Ahmet Aziz Beşli

Hi!

Updated on July 09, 2022

Comments

  • Ahmet Aziz Beşli
    Ahmet Aziz Beşli almost 2 years

    I have a problem with Google login. I want to login to my account but Google says that automation drivers are not allowed to log in.

    I am looking for a solution. Is it possible to get a cookie of normal Firefox/Chrome and load it into the ChromeDriver/GeckoDriver? I thought that this can be a solution. But I am not sure is it possible or not..

    Looking for solutions...

    enter image description here

    Also, I want to add a quick solution. I solved this issue by using one of my old verified account. That can be a quick solution for you.