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

Wednesday, October 26, 2022

[FIXED] How to locate Instagram Follow button with selenium (Python)

 October 26, 2022     instagram, python, selenium, web-scraping     No comments   

Issue

I'm trying to locate the 'follow' button element on an instagram page (using selenium).

I've found the main 'follow' button of a user's page (https://www.instagram.com/USERNAME/) with the following code:

follow_button = self.driver.find_element_by_css_selector('button')

Although after clicking the above element ^, now I'm trying to locate 'follow' buttons visible when you view a user's followers. Click here to see which buttons I'm referring to.

I've tried the following code but it doesn't work:

acc_follow_buttons = self.driver.find_elements_by_css_selector('button')

for acc in acc_follow_buttons[:15]:
    acc.click() 
    time.sleep(1)

I've also tried searching with Xpath, with no luck.

Could anyone with experience in Selenium help me with the code to locate the follow buttons on this page.


Solution

You have to search for the button by button text:

Follow_Button = driver.find_element_by_xpath("//*[text()='Follow']")


Answered By - Tommaso Montagni
Answer Checked By - David Goodson (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