I'm building an Instagram bot, and I'm trying to get it to rapidly click through stories. I've found the element with Selenium:
next_button = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[contains(@class, 'FhutL')]")))
I've already tried something myself, but I don't know how to set the conditions for a clicking loop to run, or what it should iterate through.
Here's the HTML of the button:
<button aria-label="Next" >
<div ></div>
</button>
I'd really appreciate your help.
CodePudding user response:
I'd use a for loop coupled with wait for the expected condition that the item is clickable. See below:
EDIT: you have a small number of those you follow and want to handle no more storeis being available (an undetermined amount of looping).
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
i=0
while i<1:
try:
NextStory = WebDriverWait(driver, 15).until(EC.element_to_be_clickable((By.XPATH, "//*[contains(@class, 'FhutL')]")))
NextStory.click()
except:
i=1
#do the next thing...