简体   繁体   中英

Python having errors with selenium webdriver

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?

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 .

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.

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

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

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.

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/

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM