Auto comment with Facebook post with pyautogui

Viewed 196

I am writing python code to jump the mouse cursor to the comment box of a Facebook post as below to write a comment but not work, using google chrome.

import pyautogui as P 
import time
import os

def StartChrome():
    command = r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
    os.startfile(command)  
    time.sleep(10)

def PostComment(fburl, fbcmt):
    P.hotkey('ctrl', 't')
    P.typewrite(fburl.lower())
    P.typewrite('\n')
    time.sleep(10)
    
    P.press("C")
    time.sleep(2)
    P.typewrite(fbcmt)
    P.press('enter') 

StartChrome()

PostComment('https://m.facebook.com/groups/1430431143824643/posts/1896340613900358/','Welcome')

Everything worked fine (opened new tab of chrome, loaded the post successful) but mouse cursor didn't move to the "Comment" box of the post after the line P.press("C"). Do I wrong anything of using hot key of facebook?

1 Answers

Get a locationcenteronscreen with picture of the button loaded (make sure it's not scaled or edited, must be exact copy)into the argument, then call moveto function and then finally the click function, refer to document on the official site there is a tutorial on clicking buttons specifically. Or reach out to me I'd be happy to help, I use pyautogui extensively

Related