|
| 1 | +#Imports and dependencies |
| 2 | +from selenium import webdriver |
| 3 | +import time |
| 4 | +from selenium.webdriver.common.keys import Keys |
| 5 | + |
| 6 | +time_wait_sixty = 60 |
| 7 | +time_wait_four = 4 |
| 8 | + |
| 9 | +#Here the process of automation is achieved by using the framework Selenium. |
| 10 | +#Selenium is a portable framework for testing and automating web applications web applications |
| 11 | + |
| 12 | +def automate_telegram(): |
| 13 | + #Path to the chromedriver must be entered without quotations |
| 14 | + PATH = input("Enter path to the location chromedriver ") |
| 15 | + chrome_path = PATH |
| 16 | + #Initiating and setting up the driver |
| 17 | + driver = webdriver.Chrome(chrome_path) |
| 18 | + #For logging into web telegram, the user must verify the phone number |
| 19 | + URL = "https://web.telegram.org/#/login" |
| 20 | + driver.get(URL) |
| 21 | + time.sleep(time_wait_sixty) |
| 22 | + user = 1 |
| 23 | + while user: |
| 24 | + driver.find_element_by_xpath("/html/body/div[1]/div[2]/div/div[1]/div[1]/div/input").click() |
| 25 | + name = input("Enter the name of the person ") |
| 26 | + driver.find_element_by_xpath("/html/body/div[1]/div[2]/div/div[1]/div[1]/div/input").send_keys(name) |
| 27 | + time.sleep(time_wait_four) |
| 28 | + driver.find_element_by_xpath("/html/body/div[1]/div[2]/div/div[1]/div[2]/div/div[1]/ul/li").click() |
| 29 | + msg = 1 |
| 30 | + while msg: |
| 31 | + message = input("Enter message ") |
| 32 | + driver.find_element_by_xpath("/html/body/div[1]/div[2]/div/div[2]/div[3]/div/div[3]/div[2]/div/div/div/form/div[2]/div[5]").send_keys(message) |
| 33 | + driver.find_element_by_xpath("/html/body/div[1]/div[2]/div/div[2]/div[3]/div/div[3]/div[2]/div/div/div/form/div[2]/div[5]").send_keys(Keys.ENTER) |
| 34 | + print("Do you want to send another message? ") |
| 35 | + msg = int(input("Enter 1 to continue, 0 to stop ")) |
| 36 | + if msg == 0: |
| 37 | + break |
| 38 | + |
| 39 | + print("Do you want to send messages to another contact? ") |
| 40 | + user = int(input("Enter 1 to continue, 0 to stop ")) |
| 41 | + |
| 42 | + return("All messages sent") |
| 43 | + |
| 44 | +if __name__ == "__main__": |
| 45 | + automate_telegram() |
| 46 | + |
0 commit comments