Skip to content

Commit 8c7b746

Browse files
Merge pull request #2308 from sabhisharma-ise/online
added Script to Check Who is Online on Whatsapp ✅
2 parents bbca02f + fb99f42 commit 8c7b746

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

Online_on_Whatsapp/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Python Script to check who is Online on WhatsApp using Selenium
2+
3+
## Steps to use script:
4+
5+
1. Clone the Repo
6+
2. In the users.py file update the username of the contacts
7+
3. Run $ python3 who_is_online_on_whatsapp.py
8+
9+
## OUTPUT:
10+
11+
![](https://snipboard.io/mzZ4IG.jpg)

Online_on_Whatsapp/online.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from selenium.webdriver.common.keys import Keys
2+
from selenium.common.exceptions import NoSuchElementException
3+
from selenium import webdriver
4+
from selenium.webdriver.support.ui import WebDriverWait
5+
import time
6+
import users
7+
8+
9+
def checkStatus():
10+
try:
11+
browser.find_element_by_xpath(
12+
"/html/body/div[1]/div/div/div[4]/div/header/div[2]/div[2]/span"
13+
)
14+
except NoSuchElementException:
15+
return False
16+
return True
17+
18+
19+
NEWCHAT = "/html/body/div[1]/div/div/div[3]/div/header/div[2]/div/span/div[2]/div/span"
20+
SEARCH = "/html/body/div[1]/div/div/div[2]/div[1]/span/div/span/div/div[1]/div/label/div/div[2]"
21+
USER = "/html/body/div[1]/div/div/div[2]/div[1]/span/div/span/div/div[2]/div[1]/div/div/div[2]/div/div"
22+
ONLINE = "/html/body/div[1]/div/div/div[4]/div/header/div[2]/div[2]/span"
23+
24+
browser = webdriver.Chrome(executable_path=r"/Users/sanketwable/downloads/chromedriver")
25+
browser.get("https://web.whatsapp.com/")
26+
27+
print("Loading..\n")
28+
29+
wait = WebDriverWait(browser, 600)
30+
time.sleep(10)
31+
32+
for user_name in users.USERS:
33+
34+
newchat = browser.find_element_by_xpath(NEWCHAT)
35+
newchat.click()
36+
search = browser.find_element_by_xpath(SEARCH)
37+
search.send_keys(user_name)
38+
time.sleep(2)
39+
40+
user = browser.find_element_by_xpath('//span[@title="{}"]'.format(user_name))
41+
user.click()
42+
43+
time.sleep(2)
44+
45+
if checkStatus():
46+
print(user_name)
47+
print("is online\n")
48+
else:
49+
print(user_name)
50+
print("is offline\n")
51+
52+
53+
print("Done checking WhatsApp online Status")

Online_on_Whatsapp/users.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
USERS = [
2+
"Mummy jio",
3+
"didi vodafone",
4+
"Abhay Nit Mec",
5+
"dad jio",
6+
"Jiofi",
7+
"Dhanesh Kothavale",
8+
"Pravin Kardile",
9+
"Harry cse",
10+
"Nipun Nitkkr It",
11+
]

0 commit comments

Comments
 (0)