-2
I’m doing this bot to access instagram, but is presenting an error that I can not identify. I’m a beginner and I’m having trouble finding the error. If anyone can help me, I appreciate!!
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import random
class InstagramBot:
def __init__(self, username, password):
self.username = username
self.password = password
self.driver = webdriver.Firefox(executable_path=r"C:\Users\bruno\Desktop\geckodriver-v0.29.1-win64\geckodriver.exe")
def login(self):
driver = self.driver
driver.get("https://www.instagram.com/accounts/login/?hl=pt-br")
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)
brunoBot = InstagramBot("user","senha1234")
brunoBot.login()
Error:
File "c:\Users\bruno\Desktop\geckodriver-v0.29.1-win64\igBot.py", line 16, in InstagramBot
campo_usuario = driver.find_element_by_xpath("//input[@name='username']")
NameError: name 'driver' is not defined
PS C:\Users\bruno\Desktop\geckodriver-v0.29.1-win64>```
Obrigado! :)
I believe the lines from
campo_usuario
are indented wrong. Include 4 spaces for each of them.– Paulo Marques