2

I use the following code to open a Chrome window using Selenium:

from selenium import webdriver

driver = webdriver.Chrome()
driver.get("https://www.youtube.com/")

However, whenever I enter the site, I am logged out. On other sites, I can manually do so, but Google deems it unsafe to log in with Selenium.

I know that Selenium is a test browser, but is it possible to stay logged in with Selenium so that I can access my user data; or is that not the purpose of Selenium, and calling the Chrome subprocess the way to go?

niamulbengali
  • 292
  • 1
  • 3
  • 16

1 Answers1

0

To start with Selenium isn't a browser as such but a bunch of libraries which helps in simulating Browsing Context.

From the question it's not that clear why you are logged out once you login in to the site. But definitely once you are logged in using Selenium driven ChromeDriver initiated Browsing Context you must remain logged in and should be able to access your user data.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I am quoting the error message from Google: "Couldn't sign you in. This browser or app may not be secure. Learn more. Try using a different browser. If you’re already using a supported browser, you can refresh your screen and try again to sign in." – niamulbengali Nov 27 '20 at 17:24
  • 1
    @niamulbengali The error _...This browser or app may not be secure..._ can occur occurs due to numerous reasons. See: discussions [Selenium Google Login Block](https://stackoverflow.com/questions/60117232/selenium-google-login-block/60117617#60117617) and [Unable to sign into google with selenium automation because of “This browser or app may not be secure.”](https://stackoverflow.com/questions/59514049/unable-to-sign-into-google-with-selenium-automation-because-of-this-browser-or/59515341#59515341) – undetected Selenium Nov 27 '20 at 17:34
  • Yes, the exact reason is stated in the documentation as: "To help protect your account, Google doesn’t let you sign in from some browsers. Google might stop sign-ins from browsers that are being controlled through software automation rather than a human." Thank you. – niamulbengali Nov 28 '20 at 19:56
  • @niamulbengali There are a couple of things when dealing with Google accounts for which I have linked the SO discussions within my comment. But for generic cases my answer still stands valid and true :) – undetected Selenium Nov 28 '20 at 19:59
  • I see the crux is disabling a stage of security—namely, [Two-Factor Authentication](https://en.wikipedia.org/wiki/Multi-factor_authentication)—but I think that is not worth it. I am not web-scraping or testing, so I do not need a browsing context. – niamulbengali Nov 28 '20 at 20:05
  • @niamulbengali If you don't need a browsing context how do you intend to remain logged in? – undetected Selenium Nov 28 '20 at 20:07
  • I am not confident I understand the difference between "browser" and "browsing context". I was originally writing code to automatically log in to Zoom every day. I thought Selenium was the standard way, but then, there is this issue. However, it is possible to call an instance of the regular Chrome browser with subprocess without having to log in every time. Still, thanks for the help. – niamulbengali Nov 28 '20 at 20:19