|
@ -39,6 +39,10 @@ def delete_posts(driver, |
|
|
|
|
|
|
|
|
confirmation_button_exp = "//div[contains(@data-sigil, 'undo-content')]//*/a[contains(@href, 'direct_action_execute')]" |
|
|
confirmation_button_exp = "//div[contains(@data-sigil, 'undo-content')]//*/a[contains(@href, 'direct_action_execute')]" |
|
|
|
|
|
|
|
|
|
|
|
# Cannot return a text node, so it returns the parent. |
|
|
|
|
|
# Tries to be pretty resilient against DOM re-organizations |
|
|
|
|
|
timestamp_exp = "//article//*/header//*/div/a[contains(@href, 'story_fbid')]//text()/.." |
|
|
|
|
|
|
|
|
button_types = ["Delete post", "Remove Tag", "Hide from timeline"] |
|
|
button_types = ["Delete post", "Remove Tag", "Hide from timeline"] |
|
|
|
|
|
|
|
|
while True: |
|
|
while True: |
|
@ -51,7 +55,7 @@ def delete_posts(driver, |
|
|
break |
|
|
break |
|
|
|
|
|
|
|
|
post_content_element = driver.find_element_by_xpath("//article/div[@class='story_body_container']/div") |
|
|
post_content_element = driver.find_element_by_xpath("//article/div[@class='story_body_container']/div") |
|
|
post_content_ts = driver.find_element_by_xpath("//article//*/header//a[contains(@href, 'story')]") |
|
|
post_content_ts = driver.find_element_by_xpath(timestamp_exp) |
|
|
|
|
|
|
|
|
if not (post_content_element or post_content_ts): |
|
|
if not (post_content_element or post_content_ts): |
|
|
break |
|
|
break |
|
@ -67,10 +71,13 @@ def delete_posts(driver, |
|
|
actions = ActionChains(driver) |
|
|
actions = ActionChains(driver) |
|
|
actions.move_to_element(timeline_element).click().perform() |
|
|
actions.move_to_element(timeline_element).click().perform() |
|
|
|
|
|
|
|
|
|
|
|
# Wait until the buttons show up |
|
|
wait_xpath(driver, "//*[contains(@data-sigil, 'removeStoryButton')]") |
|
|
wait_xpath(driver, "//*[contains(@data-sigil, 'removeStoryButton')]") |
|
|
|
|
|
|
|
|
delete_button = None |
|
|
delete_button = None |
|
|
|
|
|
|
|
|
|
|
|
# Search for visible buttons in priority order |
|
|
|
|
|
# Delete -> Untag -> Hide |
|
|
for button_type in button_types: |
|
|
for button_type in button_types: |
|
|
try: |
|
|
try: |
|
|
delete_button = driver.find_element_by_xpath("//*[text()='{0}']".format(button_type)) |
|
|
delete_button = driver.find_element_by_xpath("//*[text()='{0}']".format(button_type)) |
|
|