-2
I’m trying to make a bot to comment alone on youtube video, it’s working normally, until it’s time to type the comment. I have already researched everything that is place and I found nothing that helps me with this. If anyone can help I thank you. Follow the code:
from selenium import webdriver
import time
class botComentario:
def __init__(self):
self.driver = webdriver.Chrome('C:/dev/chromedriver')
self.username = "email"
self.senha = "senha"
self.comentario = "comentario"
options = webdriver.ChromeOptions()
options.add_argument('lang=pt-br')
def acessarPagina(self):
self.driver.get('http://www.youtube.com.br')
time.sleep(3)
login = self.driver.find_element_by_xpath('//*[@id="buttons"]/ytd-button-renderer/a')
time.sleep(1)
login.click()
time.sleep(3)
logar = self.driver.find_element_by_xpath('//*[@id="identifierId"]')
time.sleep(1)
logar.click()
logar.send_keys(self.username)
conectar = self.driver.find_element_by_xpath('//*[@id="identifierNext"]/span')
conectar.click()
time.sleep(1)
senha = self.driver.find_element_by_xpath('//*[@id="password"]/div[1]/div/div[1]/input')
time.sleep(1)
senha.click()
senha.send_keys(self.senha)
time.sleep(1)
conectar = self.driver.find_element_by_xpath('//*[@id="passwordNext"]/span')
conectar.click()
self.driver.get('https://www.youtube.com/watch?v=ZWmuR5H4PlU')
time.sleep(3)
login = self.driver.find_element_by_xpath('//*[@id="buttons"]/ytd-button-renderer/a')
login.click()
time.sleep(3)
self.driver.execute_script("window.scrollTo(0, 4000)")
time.sleep(5)
sessao = 0
while sessao == 0:
time.sleep(5)
comentario = self.driver.find_element_by_xpath('//*[@id="simplebox-placeholder"]')
self.driver.execute_script("document.getElementById('simplebox-placeholder').click()")
comentario.send_keys(self.comentario)
time.sleep(5)
time.sleep(2)
btncoment = self.driver.find_element_by_xpath('//*[@id="submit-button"]/a')
time.sleep(3)
btncoment.click()
bot = botComentario()
bot.acessarPagina()
It returns the following error: Traceback (Most recent call last): File "botcomentador.py", line 60, in bot.accessPagina() File "botcomentador.py", line 49, in acessarPagina comment.send_keys(self.comment) File "C: Users Appdata Local Programs Python Python38-32 lib site-Packages Selenium webdriver remote webel self. _execute(Command.SEND_KEYS_TO_ELEMENT, File "C: Users Appdata Local Programs Python Python38-32 lib site-Packages Selenium webdriver remote webel , screen, stacktrace) Elementnotinteractableexception: Message: element not interactable (Session info: Chrome=81.0.4044.92)
Thanks bro helped a lot, I’m new in Python and I like the language a lot, da para fazer muita coisa com ela.
– FioritoN
Continue is an excellent language and good studies.
– Jefferson Matheus Duarte