0

I am having errors trying to use selenium webdriver with Chrome in Windows 10.

This is my code:

import time
from selenium import webdriver

driver = webdriver.Chrome()

And this is what I get:

Traceback (most recent call last): File "C:\Users\angrypig\Desktop\Angrypig\Program Files#Projects\Python\SeleCrawler_1\SeleCrawler_1\SeleCrawler_1.py", line 10, in driver = webdriver.Chrome() AttributeError: module 'selenium.webdriver' has no attribute 'Chrome'

I already installed selenium and have chromedriver in C: but no success.

Any help please?

angrypig7
  • 9
  • 1
  • 3
  • 8

7 Answers7

3

It seems you haven't installed the selenium package, if so:

pip install selenium

However, it also seems you are using the wrong class, so this might solve your problem:

driver = webdriver.Chrome()

If the previous line did not work, so try this

driver = webdriver.Chrome('path/to/chromedriver')

Update:

I found here:

Ensure Chromium/Google Chrome is installed in a recognized location ChromeDriver expects you to have Chrome installed in the default location for your platform. You can also force ChromeDriver to use a custom location by setting a special capability.

lmiguelvargasf
  • 63,191
  • 45
  • 217
  • 228
  • yes, I installed the selenium package via pip already. And, the Chrome in lower case was just to see if that worked after webdriver.Chrom() didn't work at all. Sorry for the mistake – angrypig7 Aug 12 '17 at 02:20
  • @angrypig7, so it seems you have a typo in the class `chrome`, change it to `Chrome`. – lmiguelvargasf Aug 12 '17 at 02:22
  • Yes, that was also a mistake when posting into stackoverflow. I tried that after findin out that uppercase letters also didn't work. – angrypig7 Aug 12 '17 at 02:27
  • Just did that. Nothing seems to have changed. – angrypig7 Aug 12 '17 at 02:33
  • The chromedriver is in C:\webdriver\chromdriver.exe Then it should be like webdriver.Chrome('C:\webdriver') right? If so, still no luck – angrypig7 Aug 12 '17 at 02:39
  • that didn't work either. I tried a lot of ways in specifying paths but none of them seems to be working. – angrypig7 Aug 12 '17 at 02:45
  • Hmm, I have google chrome in the defaullt directory, so that shouldn't be a problem here. – angrypig7 Aug 12 '17 at 04:37
  • " the default location for your platform" but where is *that*? (I came across a link earlier, with the list of platforms -> locations, but lost it...!) – Andy Hayden Apr 06 '18 at 05:31
  • @AndyHayden, in a UNIX based operating system you can see the location of `chromedriver` by `$ which chromedriver`. You can also check [this link](https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver) that shows where this driver is installed by default. – lmiguelvargasf Apr 06 '18 at 12:05
  • I think it's actually talking about the location of Chrome. But yes, that's the link which shows the default Chrome binary location, thanks! – Andy Hayden Apr 06 '18 at 15:06
0

From your error message I am guessing you are working on windows and did you install chromedriver ? If not, you can do it from here:

  • Download from here

Change chrome to Chrome. Then, this should work:

from selenium import webdriver
driver = webdriver.Chrome()

Please refer this thread as well.

PseudoAj
  • 5,234
  • 2
  • 17
  • 37
0

I have run into this issue and solved it by just importing selenium, then doing:

driver = selenium.webdriver.Chrome(executable_path="PATH\TO\chromedriver.exe")

Hopefully it helps

AMC
  • 143
  • 1
  • 8
  • Thanks for your helpt but, this is what I get - NameError: name 'selenium' is not defined – angrypig7 Aug 12 '17 at 02:47
  • After adding "import selenium" instead of "from selenium import webdriver", I get this error: AttributeError: module 'selenium.webdriver' has no attribute 'Chrome' – angrypig7 Aug 12 '17 at 02:52
  • This is very strange. I pasted that directly from a working module I wrote and use every day. You should try to uninstall and re-install selenium or doing an update, because something may have been corrupted when installing or something – AMC Aug 12 '17 at 03:11
  • Also, another thing that I remember using once was doing a `from selenium import *` before the other imports, but really don't know if this would do anything – AMC Aug 12 '17 at 03:54
0

It is not enough to install selenium. Have you downloaded and put the Chrome driver where it needs to be?

From here: https://sites.google.com/a/chromium.org/chromedriver/downloads

Jugurtha Hadjar
  • 441
  • 3
  • 7
0

I just got an answer to this: Visual Studio was the problem. I tried PyCharm and it just works. heh

I have no idea what caused Visual Studio to put off errors.

angrypig7
  • 9
  • 1
  • 3
  • 8
0

I had this problem also. What ended up happening for me was when I installed selenium using pip install -U selenium in command prompt it missed putting the selenium folder in the python library.

What fixed it for me was going to https://pypi.python.org/pypi/selenium, downloading the "selenium-3.11.0.tar.gz (md5)". Unzip that and copy the selenium folder over to your python library.

This is also refreanced in part 2. Selenium installation here: https://www.kainos.pl/blog/first-test-python-webdriver-pycharm/

Onion
  • 1
0

I was facing the same error AttributeError: module 'selenium.webdriver' has no attribute 'Chrome' . Earlier I just copied and pasted the selenium library in my venv libs .But the copy was not made properly. That's why it was not working well. Since I receive this error , I removed the selenium package and installed it by pip using the command pip install selenium.It worked for me .

So What I came up to is this issue is regarding the installation of selenium.if it is not working in your code also, go and try removing the package or just uninstalling the package and install it again.

Saloni Sinha
  • 71
  • 1
  • 2