0

I have this problem with selenium, i try to run my code below but i have this error: https://i.postimg.cc/VNd3F4rm/u2zrn.jpg .

Image of my "Signing in to Google": https://i.stack.imgur.com/w3POX.png (As you can see "App password" does not appear to me)

I have already tried to disable the "less secure apps" section in account settings and checked if JavaScipt was actived, but without success.

 WebDriver driver= new ChromeDriver();
         driver.navigate().to("https://accounts.google.com/signin");

driver.findElement(By.name("identifier")).sendKeys("email@gmail.com");
         driver.findElement(By.xpath("/html/body/div[2]/div[2]/div[2]/div/div[2]/div/div/div[2]/div/div[2]/div/div[2]/div/div/button")).click();

driver.findElement(By.name("password")).sendKeys("*******");




Symoon98
  • 21
  • 1
  • 5
  • Have you made any progress? – hfontanez Feb 07 '21 at 20:56
  • No, nothing to do. When I activeted "2-Step Verification", Google doesn't let me disable the section "less secure app". Even if I set an app passoword, Google notes that I'm using a Selenium bot – Symoon98 Feb 08 '21 at 15:16

2 Answers2

0

I believe you need to go to your Google Account settings and under Security, you need to register your test app with a password. I had to do this in order to implement in Cucumber a way to send and read emails.

enter image description here

Then, from your test application, you will use those credentials (not your real Google creds) to authenticate and do what you need. You could also try this.

hfontanez
  • 5,774
  • 2
  • 25
  • 37
  • There isn't the section "App password". It could be an old image? – Symoon98 Feb 05 '21 at 23:10
  • Unless Google changed it less than 2 hours ago, the image is recent. I literally took it seconds before I posted it. – hfontanez Feb 06 '21 at 01:07
  • I really don'y know if this section is aviable in every country and if that's actually the reason why this doesn't appear to me. I can see only 3 section: The first one is "Password" (as your), the second one is "Use your phone to sign in" and the third one is "2-Step Verification". I allegate you the picture in my question box. – Symoon98 Feb 06 '21 at 16:15
  • 1
    I activeted "2-Step Verification" and now I can see the "App password" section – Symoon98 Feb 06 '21 at 16:27
0

I have another solution in python that might help you. Use Seleniumwire with undetected browser v2

Note: put chromedriver in your sys path.

from seleniumwire.undetected_chromedriver.v2 import Chrome, ChromeOptions
import time

options = {}
chrome_options = ChromeOptions()
chrome_options.add_argument('--user-data-dir=hash')
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--incognito")
chrome_options.add_argument("--disable-dev-shm-usage")
# chrome_options.add_argument("--headless")
browser = Chrome(seleniumwire_options=options, options=chrome_options)

browser.get('https://gmail.com')
browser.find_element_by_xpath('//*[@id="identifierId"]').send_keys('your-email')
browser.find_element_by_xpath('//*[@id="identifierNext"]/div/button').click()
time.sleep(5)
browser.find_element_by_xpath('//*[@id="password"]/div[1]/div/div[1]/input').send_keys('you-password')
browser.find_element_by_xpath('//*[@id="passwordNext"]/div/button').click()

In addition to this, selenium wire has many awesome features, check out Github repository

Anandesh Sharma
  • 436
  • 6
  • 22