Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

Python 3 Selenium Script to Login on Gmail Automatically in Browser

Posted on January 14, 2023

 

 

SOURCE CODE

 

 

First of all you need to install the below library using the pip command as shown below

 

 

pip install selenium

 

 

Now you need to make an app.py file and copy paste the following code

 

 

app.py

 

 

 

Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
 
print('Enter the gmailid and password')
gmailId, passWord = map(str, input().split())
try:
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get(r'https://accounts.google.com/signin/v2/identifier?continue='+\
'https%3A%2F%2Fmail.google.com%2Fmail%2F&service=mail&sacu=1&rip=1'+\
'&flowName=GlifWebSignIn&flowEntry = ServiceLogin')
driver.implicitly_wait(15)
 
loginBox = driver.find_element_by_xpath('//*[@id ="identifierId"]')
loginBox.send_keys(gmailId)
 
nextButton = driver.find_elements_by_xpath('//*[@id ="identifierNext"]')
nextButton[0].click()
 
passWordBox = driver.find_element_by_xpath(
'//*[@id ="password"]/div[1]/div / div[1]/input')
passWordBox.send_keys(passWord)
 
nextButton = driver.find_elements_by_xpath('//*[@id ="passwordNext"]')
nextButton[0].click()
 
print('Login Successful...!!')
except:
print('Login Failed')

 

 

As you can see we are automatically opening the browser tab and going to the gmail login page and automatically filling out the username and password and clicking the submit button to login as shown below

 

 

 

 

Recent Posts

  • Android Java Project to Crop,Scale & Rotate Images Selected From Gallery and Save it inside SD Card
  • Android Kotlin Project to Load Image From URL into ImageView Widget
  • Android Java Project to Make HTTP Call to JSONPlaceholder API and Display Data in RecyclerView Using GSON & Volley Library
  • Android Java Project to Download Youtube Video Thumbnail From URL & Save it inside SD Card
  • Android Java Project to Embed Google Maps & Add Markers Using Maps SDK
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme