【问题标题】:ModuleNotFoundError: No module named 'selenium' messageModuleNotFoundError:没有名为“selenium”的模块消息
【发布时间】:2021-02-02 20:50:40
【问题描述】:

我正在尝试通过 Python 脚本发送 Whatsapp 消息,因此我使用以下代码:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time

driver = webdriver.Chrome(r'''Z:\foo\bar\geckodriver.exe''') 
driver.get("https://web.whatsapp.com/")
wait = WebDriverWait(driver, 600) 
target = '"Target_Name"'
string = "Text to send"
x_arg = '//span[contains(@title,' + target + ')]'
group_title = wait.until(EC.presence_of_element_located((By.XPATH, x_arg)))
group_title.click()
inp_xpath = '//*[@id="main"]/footer/div[1]/div[2]/div/div[2]'
input_box = wait.until(EC.presence_of_element_located((By.XPATH, inp_xpath)))
for i in range(100):
    input_box.send_keys(string + Keys.ENTER)
    time.sleep(1)

但是如果我运行代码,我总是收到消息“ModuleNotFoundError: No module named 'selenium'”,尽管我在我的 cmd 中使用“pip install selenium”安装了 selenium 模块,所以它应该在计算机上。 我的操作系统是 Windows。

【问题讨论】:

标签: python selenium


【解决方案1】:

尝试使用此命令更新您的 selenium 版本,也许会有所帮助:

python -m pip install -U selenium

【讨论】:

  • 我已经尝试过了,但它根本没有帮助。会不会是版权问题之类的?
【解决方案2】:

如果您的计算机上安装了 anaconda,则可以将其安装为“conda install selenium”或“pip3 install selenium”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-08
    • 2019-03-28
    • 2017-10-15
    • 2022-01-07
    • 2017-12-14
    • 2020-12-10
    • 2021-09-02
    相关资源
    最近更新 更多