0

just started with both python and selenium and i'm trying to make a script that logs into facebook, then searches for certain person and sends some message, but i have no idea how do i focus facebook's message div. tried both

browser.execute_script("document.querySelector('._1mf').click();")

and

searchBar = browser.find_element_by_class_name('_4po3')

but it seems like the right element loads after you click on the messagebox so i tried multiple different classnames and still i'm stucked :/

EDIT: just to be clear i managed to grab specific person from the chat bar by

searchBarAfterUpdate = browser.find_element_by_xpath( "//div[@class = '_364g' and text() = 'personname']") searchBarAfterUpdate.click()

and now when i have the chat box open i want to somehow write and send a message

  • You can wait until everything loads. See here: https://stackoverflow.com/questions/26566799/wait-until-page-is-loaded-with-selenium-webdriver-for-python. Always check for existing answers first. – ba_ul Oct 06 '19 at 09:13
  • it loads after you click or focus message box , if you don't it wont load. I always check for existing answers first, that's why it's my first post after ~half year of learning – Piotr Szocik Oct 06 '19 at 09:18
  • turned out that after message box popped up you can "switch_to_active_element" and then send_keys :P – Piotr Szocik Oct 06 '19 at 11:38
  • OK. I see. That wasn't clear to me. – ba_ul Oct 06 '19 at 12:22
  • Facebook is notoriously difficult to automate from a UI perspective. If you continue running into issues down the line, this may have something to with facebook itself and not selenium. – CEH Oct 06 '19 at 15:08
  • Those classes are dynamic. You would need to use text on the page instead. – pguardiario Oct 06 '19 at 23:35
  • that's what i thought, thank you for your answers :) – Piotr Szocik Oct 07 '19 at 17:19

0 Answers0