Skip to content

Instantly share code, notes, and snippets.

@Abhayparashar31
Last active November 24, 2022 17:39
Show Gist options
  • Save Abhayparashar31/1894e77caa719e750c58a98089e57068 to your computer and use it in GitHub Desktop.
Save Abhayparashar31/1894e77caa719e750c58a98089e57068 to your computer and use it in GitHub Desktop.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options
import time
from selenium.webdriver.common.action_chains import ActionChains
PATH = 'chromedriver.exe'
##### Handling of Allow Pop Up In Facebook
option = Options()
option.add_argument("--disable-infobars")
option.add_argument("start-maximized")
option.add_argument("--disable-extensions")
# Pass the argument 1 to allow and 2 to block
option.add_experimental_option("prefs", {
"profile.default_content_setting_values.notifications": 2
})
driver = webdriver.Chrome(chrome_options=option, executable_path=PATH)
driver.maximize_window()
driver.get("https://www.facebook.com/")
###Login To The Account
def login(id,password):
email = driver.find_element_by_id("email")
email.send_keys(id)
Password = driver.find_element_by_id("pass")
Password.send_keys(password)
button = driver.find_element_by_id("u_0_b").click()
pass
#### Post Content On FaceBook
def post_content(post):
button = driver.find_element_by_class_name("sx_0b6f88").click()
time.sleep(3) ## A 3 second break in the program so that everythin loads perfectly
actions= ActionChains(driver) ##Action Chains
actions.send_keys(Keys.TAB) ##Press TAB
actions.send_keys(Keys.ENTER) ##Press ENTER
actions.send_keys(post)
actions.send_keys(Keys.TAB * 10) ### Press TAB 10 Times to reach POST button
actions.send_keys(Keys.ENTER) ### Press ENTER to post the content on facebook
actions.perform() ## To perfrom all the operations in the action chains
pass
login("YOUR_FACEBOOK_ID","YOUR_FACEBOOK_PASSWORD")
time.sleep(5)
content = "I am a Bot Posting On Facebook" ## Demo Content
post_content(content)
@christian482
Copy link

i got this error:
Message: no such element: Unable to locate element: {"method":"css selector","selector":".sx_0b6f88"}
(Session info: chrome=98.0.4758.82)
Stacktrace:
Backtrace:

i tried fin byxpath but i cant find

@DanielBooysenjr
Copy link

i got this error: Message: no such element: Unable to locate element: {"method":"css selector","selector":".sx_0b6f88"} (Session info: chrome=98.0.4758.82) Stacktrace: Backtrace:

i tried fin byxpath but i cant find

Getting the same error. Did you find a solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment