Browse Source

Wrap selector logic in try..except statement

This catches all errors that are thrown, when any
`find_element_by_*` method fails for some reason.
If this happens, we just fall through and wait for
a page refresh and then try again.
pull/8/head
Michael Gecht 6 years ago
parent
commit
22e30f300d
  1. 3
      deletefb/deletefb.py

3
deletefb/deletefb.py

@ -103,6 +103,7 @@ def delete_posts(user_email_address,
driver.get(user_profile_url) driver.get(user_profile_url)
for _ in range(MAX_POSTS): for _ in range(MAX_POSTS):
try:
post_button_sel = "_4xev" post_button_sel = "_4xev"
timeline_element = driver.find_element_by_class_name(post_button_sel) timeline_element = driver.find_element_by_class_name(post_button_sel)
actions = ActionChains(driver) actions = ActionChains(driver)
@ -124,6 +125,8 @@ def delete_posts(user_email_address,
# Facebook would not let me get focus on this button without some custom JS # Facebook would not let me get focus on this button without some custom JS
driver.execute_script("arguments[0].click();", confirmation_button) driver.execute_script("arguments[0].click();", confirmation_button)
except:
pass
# Required to sleep the thread for a bit after using JS to click this button # Required to sleep the thread for a bit after using JS to click this button
time.sleep(5) time.sleep(5)

Loading…
Cancel
Save