0

I want to create a script to automate the sending of Facebook comments. Logging in and fetching the post are done, but I cannot understand why selenium doesn't find the comment class.

Here's the code:

def fb_login():
    browser.get("https://www.facebook.com")
    time.sleep(5)
    email = browser.find_element_by_id("email")
    email.send_keys(fb_email)
    pwd = browser.find_element_by_id("pass")
    pwd.send_keys(fb_pass)
    login = browser.find_element_by_id("loginbutton")
    login.click()
    time.sleep(5)

def fb_page():
    browser.get(fb_post)


def fb_comment():
    browser.find_element_by_class_name("._5rpu")
    textbox.send_keys(fb_message)
    textbox.send_keys(Keys.ENTER)
    textbox.clear()

browser = webdriver.Firefox()
fb_login()
fb_page()
fb_comment()

Here's the exception:

selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: ._5rpu
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437

1 Answers1

1

It looks like you didn't click the "Comment" button, so the element with class name "_5rpu" is not yet generated.

Sorry I don't have enough posts to add a comment.

Viet Pham
  • 214
  • 2
  • 5
  • Finally, thank you so much, it's still the same, even though the input seems to be visible and the placeholder as well, the textbox is not there until you click on the comment button or the input area, although using class names isn't the best way to find items because they are generated, this was really helpful – SDIDSA May 04 '20 at 18:48