Black Eyed Beans
Black Eyed Beans

Reputation: 259

How to click the follow button on Instagram?

I am trying to click the follow button on Instagram using Python Selenium https://www.instagram.com/luvly_zuby/?hl=en

I've tried the bellow code but it's not working.

#click follow
    follow = driver.find_element_by_partial_link_text("Follo")
ActionChains(driver).move_to_element(follow).click().perform()

Upvotes: 0

Views: 501

Answers (3)

frianH
frianH

Reputation: 7563

Try to find the element using this css selector a.BY3EC > button and wait using .element_to_be_clickable:

follow = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'a.BY3EC > button')))
follow.click()

Following import:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

Upvotes: 0

Akshay
Akshay

Reputation: 169

This should work for you. Pass the WebElement to click(element) method.

from selenium import webdriver
driver = webdriver.Chrome()
driver.get('testUrl')
follow = driver.find_element(By.XPATH, '//button[contains(text(),'Follow')]')
webdriver.ActionChains(driver).move_to_element(follow).click(follow).perform()

Upvotes: 0

Sameer Arora
Sameer Arora

Reputation: 4507

You can click on the element by using simple selenium click by finding the element using its text in the xpath and then using explicit wait on the element.
You can do it like:

follow_button = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//button[text()='Follow']")))
follow_button.click()

You need to add the following imports:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

Upvotes: 1

Related Questions