0

I've been trying to like the posts in my feed by using Selenium but so far have had no luck

Here is my code:

like_buttons = chrome.find_elements_by_xpath("//article//section//button//*[@aria-label='Like']")
    for button in like_buttons:
        button.click()
        time.sleep(1)

I get this error:

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
toyota Supra
  • 3,181
  • 4
  • 15
  • 19

1 Answers1

0

Try this:

wait = WebDriverWait(driver, 30)
like_buttons = wait.until(EC.visibility_of_all_elements_located(By.XPATH, "//article//section//button//*[@aria-label='Like']"))
for button in like_buttons:
    button.click()
    time.sleep(1)

Or this:

wait = WebDriverWait(driver, 30)
like_buttons = wait.until(EC.visibility_of_all_elements_located(By.XPATH, "//article//section//button//*[@aria-label='Like']"))
for button in like_buttons:
    driver.execute_script("arguments[0].click();", button)
    time.sleep(1)

Imports:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Shawn
  • 4,064
  • 2
  • 11
  • 23
  • Hello Thanks for your answer , on this line "like_buttons = wait.until(EC.visibility_of_all_elements_located(By.XPATH, "//article//section//button//*[@aria-label='Like']")) " it gave me unexpected argument error so i wrote the code like this "like_buttons = wait.until(EC.visibility_of_all_elements_located((By.XPATH, "//article//section//button//*[@aria-label='Like']")))" In the end it gave a TimeoutException error on that line. – Fadopamine Apr 19 '23 at 05:04
  • Maybe i have the wrong xpath idk – Fadopamine Apr 19 '23 at 06:25