1

I am trying to use Selenium with Python 3. I installed Selenium and Chrome Webdriver. Pip was pre-installed with Python 3. However, i am getting this error message. I literally started learning this language yesterday, so please be kind if the error is silly.

Code

from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.google.com/")
driver.close()

Error message

"C:\Users\...\PycharmProjects\untitled\venv\Scripts\python.exe" 
"C:/Users/.../.PyCharmCE2018.1/config/scratches/Hello World.py"
Traceback (most recent call last):
File "C:/Users/.../.PyCharmCE2018.1/config/scratches/Hello World.py", line 4, in <module>
driver = webdriver.Chrome()
AttributeError: module 'selenium.webdriver' has no attribute 'Chrome'
Process finished with exit code 1

Any help will be appreciated.Thanks.

Innat
  • 16,113
  • 6
  • 53
  • 101
  • Somehow I still can't relate the error at `Hello World.py", line 4` with the line of code `driver.close()` in your script. Am I missing something? – undetected Selenium May 14 '18 at 19:30
  • Possible duplicate of [Python : no module named selenium](https://stackoverflow.com/questions/48267633/python-no-module-named-selenium) – undetected Selenium May 14 '18 at 19:32
  • It looks like the selenium package is not installed correctly. – jbch May 14 '18 at 21:29
  • It does not work when I try to run it by PyCharm. It seems to work otherwise. How do I fix this? –  May 15 '18 at 03:19
  • @VrajShroff i ran your code and it didn't run. After i included **chrome driver executable path** and it ran properly. Did you try my following answer. I'm pretty sure it will solve your problem. However, without PyCharm , did you try to run your code on another IDE ? – Innat May 15 '18 at 05:07
  • @VrajShroff and recheck if selenium is installed properly or install it - `pip install selenium` command. Please, let's inform your action on this. – Innat May 15 '18 at 05:59
  • Possible duplicate of [Python Selenium Chrome Webdriver](https://stackoverflow.com/questions/42478591/python-selenium-chrome-webdriver) – Innat May 15 '18 at 11:01
  • @VrajShroff please check [this](https://stackoverflow.com/a/42478941/9215780). You'll get the answer and please let me know. – Innat May 15 '18 at 11:03
  • @VrajShroff I would guess that your Pycharm project is using a different virtual environment than when you are running outside pycharm. You have to install selenium in the virtualenv set in your pycharm project: `C:\Users\Vraj Shroff\PycharmProjects\untitled\venv\Scripts\pip.exe install selenium` – jbch May 15 '18 at 15:07
  • @iPhoton unfortunately your answer did not fix it. I am not entirely sure what jbch means but the following (my answer) fixed the issue. It might be what you are hinting at. –  May 15 '18 at 16:05
  • @VrajShroff in which IDE you're running your code ? PyCharm ? Did you try to run your code in sublime or jupyter notebook ? – Innat May 15 '18 at 16:09
  • Yes, I was trying PyCharm. Unfortunately, I do not have access to any other IDE. Thanks for your help! –  May 15 '18 at 16:13

2 Answers2

1

For that you have to download the stable release of Chromedriver, Then it will work

go to this link and download it - https://sites.google.com/a/chromium.org/chromedriver/home

-2
    from selenium import webdriver
    url = 'https://mail.protonmail.com/create/new?language=en'
    driver.get(url)

It should work. It worked for me :)