I'm trying to build a code to check if a phone number exists or not and I'm using WhatsappWeb and Selenium to do so.
I'm trying the following script:
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
from selenium.common.exceptions import NoSuchElementException
driver = webdriver.Chrome(r'C:\Users\Martin\Desktop\Python Project\whatsappsms\chromedriver_win32\chromedriver')
driver.implicitly_wait(15)
driver.get('https://web.whatsapp.com')
time.sleep(5)
driver.execute_script("window.open('');")
driver.switch_to.window(driver.window_handles[1])
driver.get('https://api.whatsapp.com/send?phone=355692020202')
driver.find_element_by_xpath('// *[ @ id = "action-button"]').click()
driver.find_element_by_xpath('// *[ @ id = "fallback_block"] / div / div / a').click()
time.sleep(2)
if
driver.find_element_by_xpath('/html/body/div[1]/div/div/div[4]/div/header/div[2]/div[1]/div/span').get_attribute('innerHTML') == '+355 69 202 0202':
print("script executed, number exists")
else:
pass
class_EL= driver.find_elements_by_class_name('_3lLzD')
for i in class_EL:
if (i.get_attribute('innerHTML')) == 'Phone number shared via url is invalid.':
print("script executed, number does not exist")
else:
pass
From my point of view it will show the popup modal class if the number does not exist and it will go to the chat page if the number exists, but cant find a way to link both conditions.
Thanks in advance