0

I'm trying to send a Whatsapp-Message via a Python script, therefor I'm using the following code:

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)

But if I run the code, I always receive the message "ModuleNotFoundError: No module named 'selenium'", although I installed the selenium module in my cmd using "pip install selenium", so it should be on the Computer. My OS is Windows.

O. Schultz
  • 155
  • 1
  • 3
  • 12
  • Try this: https://stackoverflow.com/questions/44005950/from-selenium-import-webdriver-modulenotfounderror-no-module-named-selenium. – Ratmir Asanov Apr 09 '18 at 14:34
  • Possible duplicate of [Cannot import a python module that is definitely installed (mechanize)](https://stackoverflow.com/questions/14295680/cannot-import-a-python-module-that-is-definitely-installed-mechanize) – ivan_pozdeev Apr 09 '18 at 16:50
  • Also relevant: https://stackoverflow.com/questions/32680081/importerror-after-successful-pip-installation – ivan_pozdeev Apr 09 '18 at 16:52
  • Possible duplicate of [Python : no module named selenium](https://stackoverflow.com/questions/48267633/python-no-module-named-selenium) – undetected Selenium Apr 10 '18 at 05:47
  • Thanks for all the advice, but that's not my problem, I've tried everything, but it still doesn't work for me. I really don't know what's the problem here. – O. Schultz Apr 10 '18 at 09:29

2 Answers2

0

Try updating your selenium version using this command, maybe it helps:

python -m pip install -U selenium

  • I already tried this and it doesn't help at all. Is it possible that it's a problem with the rights or something like this? – O. Schultz Apr 09 '18 at 14:24
0

If you have anaconda installed on your computer, you can install it as "conda install selenium" or "pip3 install selenium".

burak
  • 1
  • 1