ethanXWL / Python-Selenium-Facebook-group-auto-poster

A Python script use Selenium to achieve automatically posting images with text on multiple Facebook groups that you are member.
50 stars 22 forks source link

Error While Sending Keys #1

Open sheinfeld opened 4 years ago

sheinfeld commented 4 years ago

Hey there,

Upon using your script, I got some errors, in specific when It was writing the message of the post:

Traceback (most recent call last): File ".\fb-group-poster.py", line 78, in <module> main() File ".\fb-group-poster.py", line 58, in main post_box.send_keys(message) File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\selenium\webdriver\remote\webelement.py", line 479, in send_keys 'value': keys_to_typing(value)}) File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute return self._parent.execute(command, params) File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable (Session info: chrome=77.0.3865.90)

andrewka85 commented 4 years ago

@sheinfeld did you ever get this to work?

andrewka85 commented 4 years ago

I am trying to do the same script, but it is not working, it cannot find some elements by xpath on the page, im also just confused if Facebook allows bots to do this

Malafur commented 3 years ago

I had the same issue, fixed it by adding some delay to the code to let the page load fully and accept the cookies popup, I'll provide a part of the code here. If it does not work let me know. I'm working to further improve the code and make it fully usable again.

Code

# Login Facebook
options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications" : 2}
options.add_experimental_option("prefs",prefs)
driver = webdriver.Chrome(options=options)
driver.get('https://www.facebook.com')
emailelement = driver.find_element(By.XPATH,'//*[@id="email"]')
emailelement.send_keys(account)
passelement = driver.find_element(By.XPATH,'//*[@id="pass"]')
passelement.send_keys(password)
#Pauses the code to let the page load, adjust for slower internet connections
time.sleep(1)
#Accepts all cookies
cookieselement = driver.find_element(By.XPATH, '//*[@title="Accept All"]').click()
loginelement = driver.find_element(By.XPATH,'//*[@name="login"]').click()
time.sleep(2)