How to handle browser or app may not be secure issue with web driver Selenium python?
Asked Answered
C

4

7

I'm trying to automate sign in into gmail and I get to see this error.

enter image description here

I think this must be because the website is able to detect the automation and blocking it. Can you all please tell me how to overcome this? I don't see this issue with my personal account but this happens only with a common account.

Chanterelle answered 17/12, 2019 at 18:48 Comment(9)
Are you able to verify this workflow works manually?Anthiathia
Yes this is working manually.Chanterelle
If you are using Chrome try Firefox, if Firefox try Chrome.Anthiathia
I have tried using both the browsers but none of them worked.Chanterelle
I would suggest looking into the enable-automation flag for chromedriver, that might solve this issue. This post might help you figure that out: #50668009Basilica
@Basilica can you elaborate more on enable-automation? Is this option capable to disable websites from tracking automation?,Chanterelle
I'm not 100% sure, I know that sites can still do things to detect automation, but I think it's purpose is to relax google's security so that you can automate google accounts and such, like what you're trying to do in your question. Also I edited my previous comment to include a link with more info.Basilica
@Basilica Tried enable-automation but did not workTrigger
I have discovered a solution for this finally. I will post the solution today.Chanterelle
C
2

Changing the default selenium chrome profile of the automated browser worked for me.

Create a new Chrome profile or use an existing one with which you want to log in. Replace the default Selenium Chrome profile with your new profile. Then Turn on sync.

With this Chrome profile in place, I can skip the login steps and directly do the main process. Use: Chrome Options to add a newly created Chrome profile as an argument.

I hope this helps people who are facing similar challenges.

Chanterelle answered 18/12, 2019 at 23:28 Comment(8)
I did exactly as suggested but Chrome launched from selenium was always asked to re-sign in upon which it insisted "Couldn't sign you in". When I clicked the User logo near the address bar, for a moment it seemed to want to skip the login but after a second later it decided that a login was required.Haulage
Did you save the login credentials in your chrome profile? Try manually opening chrome browser with the chrome profile that you have created and see if it is asking for credentials.Chanterelle
Well, it did not ask for credential when I launched the browser manually but for some reason, launching the browser by selenium made google rejected it and asked to login again. There were a lot of preferences surfaced this month regarding to selenum and google (support.google.com/accounts/thread/22873505?hl=en). However, I still was not able to automate the login process with User agent changed.Haulage
Ohhh that's sad..! I was facing the same issue and struggled for one complete day to make it work.Chanterelle
@AbhishekBoorugu I can't make out head or tails of your answer. Could you please elaborate a little bit? How are you creating a new chrome profile? Is this outside of the automation launch? What do you mean by "do the main process"? How do you add chrome profile as an argument?Amontillado
@Amontillado I have used selenium to automate the process of downloading csv files from an advertising platform by google, but after few attempts we couldn't sign-in to the platform as we were hit by the blocker that you see in the screenshot above. My understanding is that, google servers were able to identify that we are using a bot because of selenium's chrome profile. In order to escape from this trap I have used my personal chrome profile in which I'm already signed-in and I can simply escape the login steps... continuing the actual file downloading process (main process - what I intend to do).Chanterelle
To create new chrome profile you can simply google - "how to create new chrome profile" it is a 5-6 steps process. To use this chrome profile in your selenium script, follow this thread: #52394908Chanterelle
@AbhishekBoorugu Beautiful method! Great work!Amontillado
K
3

In you account profile, in Security options, try setting this option: Security settings

Kirghiz answered 20/12, 2020 at 17:50 Comment(0)
C
2

Changing the default selenium chrome profile of the automated browser worked for me.

Create a new Chrome profile or use an existing one with which you want to log in. Replace the default Selenium Chrome profile with your new profile. Then Turn on sync.

With this Chrome profile in place, I can skip the login steps and directly do the main process. Use: Chrome Options to add a newly created Chrome profile as an argument.

I hope this helps people who are facing similar challenges.

Chanterelle answered 18/12, 2019 at 23:28 Comment(8)
I did exactly as suggested but Chrome launched from selenium was always asked to re-sign in upon which it insisted "Couldn't sign you in". When I clicked the User logo near the address bar, for a moment it seemed to want to skip the login but after a second later it decided that a login was required.Haulage
Did you save the login credentials in your chrome profile? Try manually opening chrome browser with the chrome profile that you have created and see if it is asking for credentials.Chanterelle
Well, it did not ask for credential when I launched the browser manually but for some reason, launching the browser by selenium made google rejected it and asked to login again. There were a lot of preferences surfaced this month regarding to selenum and google (support.google.com/accounts/thread/22873505?hl=en). However, I still was not able to automate the login process with User agent changed.Haulage
Ohhh that's sad..! I was facing the same issue and struggled for one complete day to make it work.Chanterelle
@AbhishekBoorugu I can't make out head or tails of your answer. Could you please elaborate a little bit? How are you creating a new chrome profile? Is this outside of the automation launch? What do you mean by "do the main process"? How do you add chrome profile as an argument?Amontillado
@Amontillado I have used selenium to automate the process of downloading csv files from an advertising platform by google, but after few attempts we couldn't sign-in to the platform as we were hit by the blocker that you see in the screenshot above. My understanding is that, google servers were able to identify that we are using a bot because of selenium's chrome profile. In order to escape from this trap I have used my personal chrome profile in which I'm already signed-in and I can simply escape the login steps... continuing the actual file downloading process (main process - what I intend to do).Chanterelle
To create new chrome profile you can simply google - "how to create new chrome profile" it is a 5-6 steps process. To use this chrome profile in your selenium script, follow this thread: #52394908Chanterelle
@AbhishekBoorugu Beautiful method! Great work!Amontillado
V
1

I faced this issue. I have created dummy gmail account and now my selenium script is working fine for the same and able to login successfully.

it's not working for my personal gmail account.

Thanks !!

Venipuncture answered 9/1, 2020 at 15:25 Comment(2)
I just found out that my script works with newly created account. Honestly I don't know what the difference is between my old junk account and newly created junk account. There shouldn't be any difference, settings or security options per seHaulage
I don't think you will face this challenge after signing in. For that reason you have to skip the sign in process using a chrome profile. You can create a new chrome profile, sign in and save your credentials in that profile. Now make your selenium script use that newly created chrome profile.Chanterelle
P
1

You can try undetected-chromedriver. It will not help the servers to detect Whether the request is coming from an automated browser bot.

To install you can use pip --> pip install undetected-chromedriver and the implementation will look like:

import undetected_chromedriver as uc
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

options = uc.ChromeOptions()
# Configure options as needed
# options.add_argument('--headless')  # Optional, if you don't want a GUI.
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')

driver = uc.Chrome(options=options)

# Now proceed with your automation tasks as usual

driver.get("Your url goes here!")

 

It worked for me, and helped me to crack the "sign-in with Google" option".

Profit answered 16/2 at 8:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.