1
I’m trying to create a robot to follow people on Instagram, but I saved on the most important part, to click to follow the person. I’m using the python language and the Selenium, gnt I’ve put from td, by class, xpath, link text, css and ND VAI. And yes, I am putting the correct codes without missing any letter or number and a waiting time of 35s, the page presses, but the follow button is not selected, always appears the error Nosuchelementexception. HELP ME PF
I’ve tried to:
seguir = driver.find_element_by_link_text("Seguir")
seguir.click()
I’ve tried to xpath:
seguir = driver.find_element_by_xpath(//button[@class='_5f5mN jIbKX _6VtSN yZn4P ']")
seguir.click()
I’ve also tried by class:
seguir = driver.find_element_by_class_name('_5f5mN jIbKX _6VtSN yZn4P ')
seguir.click()
And several other ways and none will. The code of the button I want to click is this:
<span class="vBF20 _1OSdk">
<button class="_5f5mN jIbKX _6VtSN yZn4P ">Seguir</button></span>
The complete code is this:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
import random
class testebot:
def __init__(self, username, password):
self.username = username
self.password = password
self.driver = webdriver.Firefox(executable_path="D:\Desktop\driver\geckodriver.exe")
def entrar(self):
driver = self.driver
driver.get("https://www.instagram.com/")
time.sleep(5)
driver.execute_script("")
campo_usuario = driver.find_element_by_xpath("//input[@name='username']")
campo_usuario.click()
campo_usuario.clear()
campo_usuario.send_keys(self.username)
campo_senha = driver.find_element_by_xpath("//input[@name='password']")
campo_senha.click()
campo_senha.clear()
campo_senha.send_keys(self.password)
campo_senha.send_keys(Keys.RETURN)
time.sleep(15)
driver.execute_script("window.open('https://www.instagram.com/tiffanymikaely/', '_blank')")
time.sleep(10)
driver.find_element_by_css_selector('button').click()
teste = testebot ('username', 'senha').entrar()
if it helps, instagram html has a flex and Event. I’m new to programming
he’s finding the button, but n clicks ;-;
– Zinum
So try this: driver.find_element_by_css_selector('button'). click(), without saving the button in a variable, and see if it can click. Which browser you are using?
– João Victor Sierra
n was tbm, firefox
– Zinum
Could you put the full code in the post? Hides passwords and confidential information
– João Victor Sierra
Okay, I’ve posted
– Zinum
I ran the code here and managed to click the follow button. I replaced the line " driver.execute_script("window.open('instagram profile url', '_Blank')")" by driver.get("instagram profile url") and it worked. It takes a while to run, so when running the program wait a few seconds after the command to click the button run.
– João Victor Sierra
VERY OBG, VERY OBG MSM, MDS OBG JOÃO VICTOR
– Zinum
you’re an angel, obg
– Zinum
Available =)
– João Victor Sierra