Reputation: 29
I writen this code to post in facebook group from desktop program but it didnnot work. I'm using python and selenium webdriver in this script.
Can someone help me?
from selenium import webdriver
from selenium.webdriver.support.ui import webDriverWait
import unittest
class post(unittest.Testcase):
def setUp(self):
self.driver = webdriver.Firefox
self.driver.get("https://www.facebook.com/<grouplink>")
def test_shar(self):
driver = self.driver
grouppost = "test"
textid = "xhpc_message_text"
buttonid = ".//*[@id='u_jsonp_25_s']/div/div[5]/div/ul/li[2]/button"
fblogopath = "(//a[contains(@href, 'logo')])[1]"
textfiledelemnt = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_id(textid))
sharebotton = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(buttonid)
textfiledelemnt.clear()
textfiledelemnt.send_keys(grouppost)
buttonid.click()
WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(fblogopath)
def tearDown(self):
self.driver.quit()
if __name__ == '__main':
unittest.main()
Upvotes: 0
Views: 6485
Reputation: 1198
def postInGroup(driver, group_url, text):
driver.get(group_url)
driver.find_element_by_name("xc_message").send_keys(text)
driver.find_element_by_name("view_post").click()
This will work for mbasic version of Facebook i.e group_url = 'https://mbasic.facebook.com/your-group-link'
The rest is same.
Upvotes: 1
Reputation: 15413
I would suggest you not to rely to WebDriver for purpose such as one you mention.
Use Graph API, here are two good examples:
1) How do I update FB Status using Python & GraphAPI
Upvotes: -1