PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, October 26, 2022

[FIXED] How to create a clicking loop with Selenium?

 October 26, 2022     bots, instagram, python, selenium     No comments   

Issue

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" class="FhutL">
<div class="coreSpriteRightChevron"></div>
</button>

I'd really appreciate your help.


Solution

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...


Answered By - Shawn Ramirez
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing