|
| 1 | +from selenium import webdriver |
| 2 | +import time |
| 3 | +from selenium.webdriver.common.keys import Keys |
| 4 | + |
| 5 | + |
| 6 | +user_id=input('Enter User Id of your Fb Account :') # Take user id and password as input from the user |
| 7 | +password=input('Enter the password :') |
| 8 | + |
| 9 | +print(user_id) |
| 10 | +print(password) |
| 11 | + |
| 12 | +cd='C:\\webdrivers\\chromedriver.exe' |
| 13 | + |
| 14 | + |
| 15 | +browser= webdriver.Chrome(cd) |
| 16 | +browser.get('https://www.facebook.com/') |
| 17 | + |
| 18 | + |
| 19 | +user_box = browser.find_element_by_id("email") # For detecting the user id box |
| 20 | +user_box.send_keys(user_id) # Enter the user id in the box |
| 21 | + |
| 22 | +password_box = browser.find_element_by_id("pass") # For detecting the password box |
| 23 | +password_box.send_keys(password) # For detecting the password in the box |
| 24 | + |
| 25 | +login_box = browser.find_element_by_id("u_0_b") # For detecting the Login button |
| 26 | +login_box.click() |
| 27 | + |
| 28 | +time.sleep(20) |
| 29 | + |
| 30 | +k='//*[@id="home_birthdays"]/div/div/div/div/a/div/div/span/span[2]' |
| 31 | +n=browser.find_element_by_xpath(k).get_attribute('textContent') |
| 32 | + # To get the number of friends to be wished |
| 33 | +num=n[0] |
| 34 | +num=int(num) |
| 35 | +print(num) |
| 36 | + |
| 37 | + |
| 38 | +message= "Happy Birthday !!" |
| 39 | +browser.get('https://www.facebook.com/events/birthdays/') |
| 40 | +#time.sleep(3) |
| 41 | + |
| 42 | +bday_list=browser.find_elements_by_xpath("//*[@class ='enter_submit uiTextareaNoResize uiTextareaAutogrow uiStreamInlineTextarea inlineReplyTextArea mentionsTextarea textInput']") |
| 43 | + |
| 44 | +c=0 |
| 45 | +for element in bday_list: |
| 46 | + element_id = str(element.get_attribute('id')) |
| 47 | + XPATH = '//*[@id ="' + element_id + '"]' |
| 48 | + post = browser.find_element_by_xpath(XPATH) #To fetch the box where to enter text |
| 49 | + post.send_keys("Happy Birthday, Best wishes.") # To enter the bday wish |
| 50 | + #time.sleep(1) |
| 51 | + post.send_keys(Keys.RETURN) #To send the wish |
| 52 | + c=c+1 |
| 53 | + if(c>num): # This prevents putting wishes for belated birthday |
| 54 | + break |
| 55 | + |
| 56 | +browser.quit() |
0 commit comments