# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---



# ## Instagram Follow Automation to Particular Accounts

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
import time
import random

# ## Step 1 - Chrome Driver

driver = webdriver.Chrome('D:\chromedriver_win32\chromedriver.exe')
driver.get('https://www.instagram.com')

# ## Step 2 - Log in

# +
username = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='username']"))).send_keys("MY_USERNAME")
password = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='password']"))).send_keys("<PASSWORD>")

try :
    submit = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH, "//button[@type='submit']"))).click()
    print('berhasil login')
except :
    print('gagal login')
# -

# ## Step 3 - Handle Alerts

notNow_alert = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH, "//button[contains(text(),'Not Now')]")))
notNow_alert.click()

# ## Step 4 - Search Account

time.sleep(1)
searchBox = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH, "//input[@placeholder='Search']")))
searchBox.send_keys('<PASSWORD>wahh')
time.sleep(1)
searchBox.send_keys(Keys.ENTER)
time.sleep(1)
searchBox.send_keys(Keys.ENTER)

# ## Step 5 - Button Follow Click

time.sleep(4)
followBtn = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH, "//button[contains(text(),'Follow')]")))
followBtn.click()

StarcoderdataJupyterScriptsDedupFiltered