from selenium import webdriver from selenium.webdriver.chrome.service import Service from webdriver_manager.chrome import ChromeDriverManager from urllib.parse import quote from time import sleep from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import WebDriverWait with open('msg2.txt', 'r') as file: msg = file.read() msg = quote(msg) number = [] with open('numbers.txt', 'r') as file: for num in file.readlines(): number.append(num.rstrip()) driver = webdriver.Chrome(service=Service(ChromeDriverManager().install())) link = 'https://web.whatsapp.com/' driver.get(link) sleep(2) WebDriverWait(driver, 40).until(EC.presence_of_element_located((By.XPATH, '//*[@id="app"]/div/div[2]/div[3]/header'))) for num in number: link2 = f'https://web.whatsapp.com/send/?phone=91{num}&text;={msg}' driver.get(link2) Pathurl = '//*[@id="app"]/div/span[2]/div/span/div/div/div/div/div/div[1]' if Pathurl=='//*[@id="app"]/div/span[2]/div/span/div/div/div/div/div/div[1]': driver.find_element(By.XPATH,'//*[@id="app"]/div/span[2]/div/span/div/div/div/div/div/div[2]/div/button/div/div').click() continue #Message #/html/body/div[1]/div/span[2]/div/span/div/div/div/div/div/div[1] #Ok #/html/body/div[1]/div/span[2]/div/span/div/div/div/div/div/div[2]/div/button/div/div # driver.find_element(By.XPATH,'//*[@id="app"]/div/span[2]/div/span/div/div/div/div/div/div[2]/div/button/div/div').click() #//*[@id="app"]/div/span[2]/div/span/div/div/div/div/div/div[1] #//*[@id="app"]/div/span[2]/div/span/div/div/div/div/div/div[2]/div/button/div/div WebDriverWait(driver, 150).until(EC.presence_of_element_located((By.XPATH, '//div[@title="Attach"]'))) sleep(2) driver.find_element(By.XPATH,'//div[@title="Attach"]').click() WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, '//span[contains(text(),"Photos & Videos")]/../input'))) image_btn = driver.find_element(By.XPATH,'//span[contains(text(),"Photos & Videos")]/../input') image_btn.send_keys('E:FITECHContactsWhatsapp send automationJava banner.png') WebDriverWait(driver, 2).until(EC.presence_of_element_located((By.XPATH, '//span[@data-icon="send"]'))) sleep(2) driver.find_element(By.XPATH,'//span[@data-icon="send"]/..').click() sleep(5) print("Done")