0

I have been trying to use python-selenium to automate the login to google, but after I enter the username and click on next I get the message

Couldn’t sign you in

That is probably because the webpage detects that the chrome browser is controlled by test automation software. But I already tried to exclude that switch using the following setup code:

options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["enable-automation"])
driver = webdriver.Chrome(options=options)

but it still does not work. I am using chrome 98.

How can I fix that problem? Or maybe there is another way to automatically log in to a google account using python-selenium and a username/password combination?

Alex
  • 41,580
  • 88
  • 260
  • 469

1 Answers1

0
mail_address = ''
password = ''

from selenium import webdriver

UA = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0'
PHANTOMJS_ARG = {'phantomjs.page.settings.userAgent': UA}
driver = webdriver.PhantomJS(desired_capabilities=PHANTOMJS_ARG)

url = 'https://www.google.com/accounts/Login?hl=ja&continue=http://www.google.co.jp/'
driver.get(url)

driver.find_element_by_id("Email").send_keys(mail_address)
driver.find_element_by_id("next").click()
driver.find_element_by_id("Passwd").send_keys(password)
driver.find_element_by_id("signIn").click()

Try this if you face issue with browser Automation Google login with python and selenium

Sushant Agarwal
  • 440
  • 4
  • 10
  • Thanks for the quick reply, but it does not work. I get the error `AttributeError: module 'selenium.webdriver' has no attribute 'PhantomJS'` – Alex Mar 05 '22 at 07:29
  • I also tried the suggestions in the link, but they also do not seem to work. – Alex Mar 05 '22 at 07:44
  • Check this link : https://stackoverflow.com/questions/47980410/module-selenium-webdriver-has-no-attribute-phantomjs – Sushant Agarwal Mar 05 '22 at 08:23
  • Yes I found the same link, but somehow it does not describe how to install that missing package. The answers only describe how to install selenium, but now how to install `PhantomJS`. – Alex Mar 05 '22 at 08:25