chromedriver问题-“可执行文件必须位于PATH中。”

时间:2020-04-28 00:39:15

标签: python selenium-chromedriver bots

我正在尝试使用python做一个WhatsApp机器人。

终端中出现以下错误:

raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: '.chromedriver.exe' executable needs to be in PATH. 
Please see https://sites.google.com/a/chromium.org/chromedriver/home

但是在与我的python脚本相同的目录中运行.exe

enter image description here

ID是什么?

代码在哪里:

from selenium import webdriver
import time


class WhatsappBot:
    def __init__(self):
        self.mensagem = "BOT TEST"
        self.grupos = ["APS jogo", "Mine"]
        options = webdriver.ChromeOptions()
        options.add_argument('land=pt-br')
        self.driver = webdriver.Chrome(executable_path=r'.chromedriver.exe')



    def EnviarMensagens(self):

        self.driver.get('https://web.whatsapp.com/')

        time.sleep(30)
        for grupo in self.grupos:
            grupo = self.driver.find_element_by_xpath(f"//span[@title='{grupo}']")
            time.sleep(3)
            grupo.click()
            chatBox= self.driver.find_element_by_class_name('_1Plpp')
            time.sleep(3)
            chatBox.click()
            chatBox.send_keys(self.mensagem)
            botaoEnviar = self.driver.find_element_by_xpath("//span[data-icon='send']")
            time.sleep(3)
            botaoEnviar.click()
            time.sleep(3)

bot = WhatsappBot()
bot.EnviarMensagens()

0 个答案:

没有答案