Struggling to access Google using Selenium automation due to the message "This browser or application may not be secure."

Whenever I attempt to log in to Google using selenium, I keep encountering the error message stating that "This browser or app may not be secure."

The code snippet I am using for the login function is:

async function loginToChrome(driver, username, password) {
  await driver.get("https://accounts.google.com/signin");
  await driver.sleep(1000);
  let email_phone = await driver.findElement(
    By.xpath("//input[@id='identifierId']")
  );
  await email_phone.sendKeys(username);
  await driver.findElement(By.id("identifierNext")).click();
  await driver.sleep(1000);

  let passEl = await driver.findElement(By.xpath("//input[@name='password']"));
  await passEl.sendKeys(password);
  await driver.findElement(By.id("passwordNext")).click();
  await driver.sleep(1000);
}

This issue seems similar to those discussed on this page and here.

I have attempted using both chrome and firefox web drivers without success. Furthermore, I tried utilizing

.excludeSwitches(['enable-automation'])
, which also proved ineffective.

It appears that the sign-in page might recognize my automated environment. I explored a potential solution involving hiding the webdriver usage as discussed here.

I examined the User-Agent factor but found that it mirrors my regular chrome user-agent.

Despite all attempts, I remain at an impasse. While some suggest using an existing user profile from a normal chrome installation, this approach does not align with my requirements.

Have any of you discovered a viable solution? My search efforts have been fruitless thus far.

EDIT: Given the recent attention this issue has received, I managed to find a workaround by switching to Puppeteer. Check out these packages:

    "puppeteer",
    "puppeteer-extra",
    "puppeteer-extra-plugin-stealth"

EDIT 2: I've noticed increased interest in this topic lately. Here is the code snippet I eventually utilized for the login process, employing puppeteer instead of selenium:

async function login(
  page: Page,
  username: string,
  password: string,
  backup: string
) {
  await page.goto("https://accounts.google.com/");

  await page.waitForNavigation();

  await page.waitForSelector('input[type="email"]');
  await page.click('input[type="email"]');

  await page.waitForNavigation();

  //TODO : change to your email
  await page.type('input[type="email"]', username);
  await page.waitForSelector("#identifierNext");
  await page.click("#identifierNext");

  await page.waitFor(1000);

  await page.waitForSelector('input[type="password"]');
  await page.click('input[type="password"]');
  await page.waitFor(500);
  //TODO : change to your password
  await page.type('input[type="password"]', password);

  await page.waitForSelector("#passwordNext");
  await page.click("#passwordNext");
  await page.waitForNavigation();
}

Answer №1

My successful approach involved the following steps: 1. Log into Stack Overflow using your Google account. 2. Once logged in, access your email.

Here is the solution:


WebDriver driver;
System.setProperty("webdriver.chrome.driver", "chromeDriver/chromedriver.exe");
driver = new ChromeDriver();
GeneralClass te = new GeneralClass();

driver.get("https://accounts.google.com/signin/oauth/identifier?client_id=717762328687-iludtf96g1hinl76e4lc1b9a82g457nn."
+ "apps.googleusercontent.com&as=JS6BM8cjL-8j9votansdkw&destination=https%3A%2F%2Fstackauth"
+ ".com&approval_state=!ChRoYWVvLUlNMk5hSXJWUGlaSVl2WBIfc3lSa0lueENpb29lSU5vbEVpbVNxcUZGaGNkSEJoYw%E2%88%99AJDr988AAAAAXlBKc7PzEomxSzgNqd4wLptVlf0Ny3Qx&oauthgdpr=1&xsrfsig=ChkAeAh8T8JNDxCf2Zah5fb_rQ55OMiF8KmMEg5hcHByb3ZhbF9zdGF0ZRILZGVzdGluYXRpb24SBXNvYWN1Eg9vYXV0aHJpc2t5c29vcGU&flowName=GeneralOAuthFlow");
te.waitingForElementSendingKey(driver, By.id("identifierId"), "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2f77777777777777776f48424e4643014c4042">[email protected]</a>");
te.waitingForElementForClickOnly(driver, By.id("identifierNext"));
te.waitingForElementSendingKey(driver, By.name("password"), "PASSWORD");
te.waitingForElementForClickOnly(driver, By.id("passwordNext"));
Thread.sleep(1500);
driver.get("https://mail.google.com/mail/u/0/#inbox");

Thank you.

Answer №2

After hours of trial and error, I finally discovered a solution that worked for me.

By adding

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

However, after further testing with a different email, I realized this initial fix did not work. Through careful observation, I found an alternative solution that has proven successful.

Automation Steps:

1. Visit 2. Select "Log in with Google Strategy" 3. Enter your Google username and password 4. Log in to Stackoverflow 5. Go to (or any desired Google app)

After consistently following these steps for approximately 24 hours, attempt automating the direct login to your desired Google app. This method has been successful for myself and others who have tried it. Note: It may be beneficial to continue with stackoverflow login until you encounter a captcha request.

Answer №3

I discovered a solution that proved effective for me - generating a Google account within the Chrome browser opened by the webdriver. By utilizing this freshly established account, I was able to resolve my issue. However, I remain unsure of the specific distinctions between this new account and others.

Answer №4

This method has been successful for me:

While I personally use Puppeteer, I believe this approach can be applied to any automated script.

It is essential to establish a userDataDirectory to allow the browser to access the same storage data.

Initially, running the script with headless: false is crucial in order to launch a browser window. Attempting to sign in on the current tab (which was automatically navigated) will result in an error upon each login try.

The technique that proved effective for me was opening a new tab, manually navigating, and then trying again.

After the initial login process, subsequent script runs should not require another login.

Answer №5

Today I encountered a similar problem and found a solution that worked for me:

  • Turn off Two Factor Authentication for your Google account before running @Test.

Details of my environment:

  • Using net6.0; coded in C#
  • Utilizing Selenium.Support (nuget) Version="4.10.0"

I attempted the following with no success:

  1. Logging into stackoverflow using a Google account.
  2. Accessing the email inbox after logging in.

Additionally, the suggested answer below did not resolve the issue:

  • Adding args:
    '--disable-web-security', '--allow-running-insecure-content'

Answer №6

Consider giving the undetected_chromedriver library a try:


!pip install undetected_chromedriver

import undetected_chromedriver as uc

driver = uc.Chrome(executable_path='chromedriver.exe') #modify for your own path

driver.get('https://accounts.google.com/ServiceLogin') 
#add your code to continue working...

It performed impressively well in my case.

Answer №7

When encountering this error message...

The current browser or application may pose security risks.
Consider trying a different browser. If you are already using a supported browser, attempt to refresh your screen and retry signing in.

This suggests that the WebDriver faced difficulties authenticating the Browsing Context or the active Browser session.


Possible Causes and Solutions

Various reasons could lead to this issue:

Solutions

To address these issues, consider the following solutions:

  • Turn off Two Factor Authentication for this particular Google account and carry out your @Test.
  • Enable access for less secure apps

Dive deeper into this topic through the discussion found at Sign in to gmail account fails (selenium automation)


tl; dr

Refer to the following documentation for further insights:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unable to assign a value to a property that does not exist

Greetings, I have come across this Node.js code snippet where a find query with mongoose is being executed. router.post('/query',function(req,res,next){ if (req.body){ var result=[]; console.log(req.body.filters); Pol ...

Is it possible to incorporate a next.js image onto the background design?

I've encountered an issue while attempting to create a fixed background image with a parallax effect using Tailwind CSS and Next.js Image. If you need to see an example of this in action, check out this Template Monster theme. Here's the code s ...

Having trouble getting a react application using Webpack 2 and code splitting to run properly without dynamic files

After creating a beautiful React app with Webpack 2 and code splitting, I now have an index.html file along with several JS apps like bundle.js, 1.bundle.js, etc. in a build folder. My initial thought was to simply serve these assets statically on a server ...

What is the best way to conceal a specific div by its ID while other divs are being displayed?

There are four divs in total, all sharing the same class. However, each div has a unique ID ranging from 1 to 4. My goal is to employ jQuery to hide 'div id 1' when any of the other divs are visible, and vice versa - meaning if 'Div Id 4&apo ...

Obtaining various values for checkboxes using dynamic data in a React application

Retrieve all checkbox values dynamically import * as React from "react"; import Checkbox from "@mui/material/Checkbox"; import FormControlLabel from "@mui/material/FormControlLabel"; import axios from "axios"; expor ...

Guide on clicking a label element with Python and Selenium

I have been working on a web scraping bot using Python and Selenium, but I've encountered an issue. The website I'm trying to scrape has a fieldset HTML tag with 4 label tags inside it. All these labels have the same class name and I need to clic ...

What could be causing the issue with the variable appearing as undefined in

My class has a property: public requestLoadPersonal: Personal[] = []; As well as a method: private filterByGender(selectedValue: any): void { console.log(this.requestLoadPersonal); this.requestLoadPersonal = this.requestLoadPersonal.filter( ...

Is there a way to mount or unmount a React component by pressing a single key?

I am currently developing an application that showcases 3D objects upon pressing certain keys on the keyboard. My goal is to have these objects disappear after 2-3 seconds or once the animation completes. Below is the component responsible for managing th ...

The request returned a 404 (Not Found) error message when trying to navigate using AngularJS

Currently, I am working on building a straightforward application using Ionic and Angular. To test my progress locally, I have set up a simple server by running Ionics ionic serve command. Below is the snippet of my playlist.html code, where I intend to s ...

Delete items from several arrays on a click event in React

I'm working with an array of objects that contain multiple arrays. My goal is to remove the item when a button is clicked, but I keep getting undefined as a result. JSON Data [ { "services": [ { "id": "1b9 ...

The application of textures is not being done correctly

Trying to incorporate two textures - one for the wall and another for the floor. However, after rendering, only a solid color is displayed instead of the desired texture. Below is the configuration of my scene and camera: const tempScene = new THREE.Sc ...

Flask not serving Favicon and images to a React application

I am currently working with a Flask server and have it set up in the following manner: app = Flask(__name__, static_folder="dist/assets", static_url_path='/assets', template_folder="dist") ...

Legend click functionality works well in hiding the bars, but unfortunately, the data values in the charts.js are not being concealed as expected

When I click on the legend, the bar is hidden in the charts.js bar chart. However, the data value associated with the bar is not hidden. I have provided a link to the JS Fiddle code below: Check out the JS Fiddle here: https://jsfiddle.net/npyvw1L8/ var ...

Image uploads are being interrupted by redirection

After submitting a form, I want the user to be redirected to another page. However, I am facing an issue with the redirection logic in my code. Although I am using window.location.href for redirection, it seems to interfere with the image uploading process ...

Looking to deactivate a particular checkbox in a chosen mode while expanding the tree branches

I encountered an issue with a checkbox tree view where I needed to disable the first two checkboxes in selected mode. While I was able to achieve this using the checked and readonly properties, I found that I could still uncheck the checkboxes, which is no ...

Chrome not displaying fonts properly

Having a font issue in Chrome where specifying "Myriad Pro", Tahoma, Arial results in weird symbols. Works fine in FF, IE, and Safari. Using font-family: Tahoma, Arial; works for all browsers including Chrome. How can Myriad Pro be achieved for IE, FF, a ...

Javascript: Iterating over a promise contained in an object

Currently, I am attempting to iterate through a return from an API that supposedly contains an object with a promise within it. You can find the API documentation here: https://github.com/sentanos/roblox-js/wiki/Main-Functions This is what my code looks ...

Upon installation, the extension that replaces the new tab fails to detect the index.html file

edit: Check out the Chrome Extension here Edit 2: It seems that the recent update containing the index.html file was not published due to Google putting it under revision. Apologies for forgetting to include the index.html file in the upload zip, as I ...

Ensuring the correct range with HTML TextBoxFor

Is there a way to validate user input in a TextBoxFor to ensure it is less than a certain number at run-time? Here is the current code snippet for reference - <div class="col-md-3 input-group"> <span class="input-group-addon ...

Tips for verifying video loading in a URL

Is there a way to validate if a video embedded in a URL, similar to YouTube URLs, loads and streams without knowing the tag name or ID of the video element? Here is a sample code using Selenium: public class URLCheck { public static void main(String ar ...