0

I'm setting up a function that auto scrolls and auto likes on Instagram but when i try run it, it either comes up with an error that element not interactable or element is not attached to the page document

I tried the time.sleep and driver.implicitly_wait to check if it because the elements haven't loaded yet

      html = self.driver.find_element_by_tag_name('html')
      while True:
          button = self.driver.find_element_by_class_name('_9AhH0') 
          time.sleep(0.5)
          html.send_keys(Keys.PAGE_DOWN)
          time.sleep(0.5)
          try:
              button.send_keys(Keys.ENTER)
              print("Like")
          except Exception as e:
              print(e)

1 Answers1

0

Try adding a wait condition before interacting with the element:

from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.ui import WebDriverWait

button= WebDriverWait(driver, 20).until(
 expected_conditions.presence_of_element_located(By.CSS_SELECTOR, "._9AhH0")).send_keys(Keys.ENTER)
Mate Mrše
  • 7,997
  • 10
  • 40
  • 77