def feed_auto_like(x):
likes = 0
like_buttons = list(driver.find_elements_by_xpath("//div[@data-testid='like']"))
while likes < x:
driver.execute_script("arguments[0].click();", like_buttons[likes])
likes += 1
print(likes, 'Sucessful Likes')
driver.execute_script("arguments[0].scrollIntoView()", like_buttons[likes])
time.sleep(5)
In this code, I search for elements once. However, I was wondering if I could somehow tell the function to search again and append it to the current list ONLY when it gets to the end of the current list. I want to prevent clicking on the same button twice, that's why.
I was considering adding this:
like_buttons.append(driver.find_elements_by_xpath("//div[@data-testid='like']"))
but if I put it inside the while loop, it'll add repetitions into the list. The search returns all the same like button with the same id. However, the position is of importance because I don't want to click it more than once.
I tried using a try-except block type; however, that was unsuccessful.