0
NameError                                 Traceback (most recent call last)
Input In [10], in <cell line: 72>()
     58     def paste_content(self, navegador, el, content):
     59         navegador.execute_script(`
     60             f'''
     61             const text = `{content}`;
   (...)
     69             ''',
     70             el)
---> 72 if _name_ == "_main_":  
     74         zap = ZapZap()
     75 zap.EnviarMsg()`

NameError: name '_name_' is not defined
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
import configparser

class ZapZap:

    def __init__(self):
        self.endereco = 'https://api.whatsapp.com/send?phone=55'
        self.numeros = [11941194455]
        self.timer = 5
        self.timer2 = 25

        config = configparser.ConfigParser()
        config.read('texto.ini', encoding='UTF-8')
        self.mensagem = config['texto']['mensagem']
        self.profile = config['caminho']['profile']

    def EnviarMsg(self):
        servico = Service(ChromeDriverManager().install())
        options = Options()
        options.add_argument(self.profile)
        navegador = webdriver.Chrome(service=servico, options=options)

        for n in self.numeros:
            navegador.get(self.endereco + str(n))
            navegador.maximize_window()
            time.sleep(self.timer)

            wait = WebDriverWait(navegador, 10)
            
            # Primeiro botão para iniciar conversa
            wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="action-button"]/span'))).click()
            time.sleep(self.timer)

            # Segundo botão para continuar no WhatsApp Web
            wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="fallback_block"]/div/div/h4[2]/a/span'))).click()
            time.sleep(self.timer2)

            # Clicar no campo de digitação
            input_el = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="main"]/footer/div[1]/div/span[2]/div/div[2]/div[1]/div/div[1]/p')))
            input_el.click()
            time.sleep(self.timer)

            # Colar a mensagem
            self.paste_content(navegador, input_el, self.mensagem)
            time.sleep(self.timer)

            wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="main"]/footer/div[1]/div/span[2]/div/div[2]/div[2]/button/span'))).click()
            time.sleep(self.timer)

    def paste_content(self, navegador, el, content):
        navegador.execute_script(
            f'''
            const text = `{content}`;`
            const dataTransfer = new DataTransfer();
            dataTransfer.setData('text', text);
            const event = new ClipboardEvent('paste', {{
              clipboardData: dataTransfer,
              bubbles: true
            }});
            arguments[0].dispatchEvent(event)
            ''',
            el)

if __name__ == "__main__":      
zap = ZapZap()
zap.EnviarMsg()
    Input In [5]
        zap = ZapZap()
        ^
    IndentationError: expected an indented block
moken
  • 3,227
  • 8
  • 13
  • 23
  • 1
    Did you look at this before you posted it? How is someone supposed to find an indentation error (or name error? That's the one that's actually shown) when they _can't see the indentation?_ – jonrsharpe Aug 24 '23 at 14:51
  • For info on formatting your post: https://stackoverflow.com/editing-help – 001 Aug 24 '23 at 14:52
  • Anyway, I think you want `__name__ == '__main__'`. Double underscores. [why \_\_name\_\_ is equal to \_\_main\_\_?](https://stackoverflow.com/q/62507698) – 001 Aug 24 '23 at 14:55
  • If the indentation is correct for `if __name__ == "__main__": ` then given this is an `if` statement the line(s) below it `zap = ZapZap()` and `zap.EnviarMsg()` must be indented. – moken Aug 27 '23 at 08:56

0 Answers0