简体   繁体   English

AttributeError 问题:模块“selenium.webdriver”没有属性“Chrome”

[英]AttributeError Issue: module 'selenium.webdriver' has no attribute 'Chrome'

webdriver 下没有 chrome 模块 I have just started Selenium using Python. And I'm facing the Attribute error issue.我刚刚使用 Python 启动了 Selenium。我正面临属性错误问题。

  • Have Installed Python 3.6.5 and installed the latest selenium packages(selenium-3.11.0)已安装 Python 3.6.5 并安装了最新的 selenium 软件包(selenium-3.11.0)

  • Have also added Scripts and Python folder path in the Environment variable: PATH .还在环境变量中添加了 Scripts 和 Python 文件夹路径: PATH

  • Downloaded the chromedriver.exe and have added the respective file path into the environment variable.下载 chromedriver.exe 并将相应的文件路径添加到环境变量中。

But while running the below code:但是在运行以下代码时:

from selenium import webdriver
driver = webdriver.Chrome("E:\Selenium\chromedriver_win32\chromedriver.exe")

It's throwing the following error:它抛出以下错误:

C:\Users\Sooraj\venv\firstpgm\Scripts\python.exe C:/Users/Sooraj/PycharmProjects/Selenium/First.py
Traceback (most recent call last):
  File "C:/Users/Sooraj/PycharmProjects/Selenium/First.py", line 2, in 
<module>
driver=webdriver.Chrome("E:\Selenium\chromedriver_win32\chromedriver.exe")
AttributeError: module 'selenium.webdriver' has no attribute 'Chrome'

Process finished with exit code 1

Tried all the other solutions provided here in Stack Overflow like uninstalling and reinstalling Python and upgrading the selenium.But was of no help.尝试了 Stack Overflow 中提供的所有其他解决方案,例如卸载和重新安装 Python 以及升级 selenium。但没有任何帮助。

The code was run using PyCharm IDE but when run using IDLE it's working fine.该代码是使用 PyCharm IDE 运行的,但是当使用 IDLE 运行时它工作正常。

Could find the folders like firefox,chrome,safari,phantomjs,android etc..under Sitepackages -> selenium -> webdriver.But not sure why it is still showing "Webdriver has no attribute chrome"可以在 Sitepackages -> selenium -> webdriver 下找到 firefox,chrome,safari,phantomjs,android 等文件夹

The above screenshot attached.附上上面的截图。 Shows no module chrome() under webdriver在 webdriver 下显示没有模块 chrome()

Any help would be appreciated.任何帮助,将不胜感激。

from selenium import webdriver

driver = webdriver.Chrome()

This is the correct way how to write that code, also if u want to use firefox or something else then change chrome to firefox ... also read 1st a documentation and look for some examples, then put it here if u find nothing这是编写该代码的正确方法,如果您想使用 firefox 或其他东西,则将 chrome 更改为 firefox ...还请阅读第一个文档并查找一些示例,如果您什么也没找到,请将其放在这里

Also use pip install selenium !也使用 pip install selenium !

You can delete the file you recently created.您可以删除您最近创建的文件。 I am facing same issue when i come to this thread and nothing worked for me.当我来到这个线程时,我面临同样的问题,但对我没有任何帮助。 I just deleted my recent file and everything works fine :-)我刚刚删除了我最近的文件,一切正常:-)

Before creating new python file selenium work fine.在创建新的 python 文件之前硒工作正常。 it start showing this error when i create new python file in same folder.当我在同一文件夹中创建新的 python 文件时,它开始显示此错误。 When i delete the file , everything work fine as before.当我删除文件时,一切正常。

您应该这样写: browser = webdriver.Chrome(executable_path=r"chromedriver.exe")并请确保您的系统上安装了 Google Chrome。

Try using following command instead尝试使用以下命令

driver = webdriver.chrome.webdriver.WebDriver(executable_path='E:\Selenium\chromedriver_win32\chromedriver.exe')

Reference: Official document https://seleniumhq.github.io/selenium/docs/api/py/webdriver_chrome/selenium.webdriver.chrome.webdriver.html#selenium.webdriver.chrome.webdriver.WebDriver参考:官方文档https://seleniumhq.github.io/selenium/docs/api/py/webdriver_chrome/selenium.webdriver.chrome.webdriver.html#selenium.webdriver.chrome.webdriver.WebDriver

first check google chrome version of your system by using this in URL chrome://version/首先在 URL chrome://version/中使用它来检查系统的 google chrome 版本

then download chrome driver from below mention website according to chrome version https://chromedriver.chromium.org/downloads然后根据 chrome 版本从下面提到的网站下载 chrome 驱动程序https://chromedriver.chromium.org/downloads

then type this in pycharm or sublime text然后在 pycharm 或 sublime 文本中输入

import selenium

from selenium import webdriver

driver = webdriver.chrome.webdriver.WebDriver(executable_path='C:/drivers/chromedriver_win32 (1)/chromedriver.exe')

driver.get("http://www.python.org")

and RUN, surely it works然后运行,肯定可以

Windows 7: Pycharm IDE version 2018.1.2 Navigate to Windows 7:Pycharm IDE 版本 2018.1.2 导航到

Project Name->venv项目名称->venv

Open pyenv.cfg打开 pyenv.cfg

Change改变

include-system-site-packages = false

to

include-system-site-packages = true

please check your filename, it is not be special name.请检查您的文件名,它不是特殊名称。 for example selectors.py例如选择器.py

use this and then hit invoke使用它然后点击调用

from selenium import webdriver driver = webdriver.Chrome(executable_path=yourpath\chromedriver.exe")从 selenium 导入 webdriver driver = webdriver.Chrome(executable_path=yourpath\chromedriver.exe")

Well what you can do is to consider this official page selenium那么你可以做的是考虑这个官方页面selenium

Three Ways to Use Drivers...三种使用驱动程序的方法...

The first way works well.第一种方法效果很好。 For this you have to install webdrivermanager为此,您必须安装 webdrivermanager

pip install webdriver-manager

and then接着

# selenium 4
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))

github link for more github链接了解更多

The issue seems with Pycharm.这个问题似乎与 Pycharm 有关。

Go to Python Packages which would be displayed at the bottom line Pycharm Image转到将显示在底线Pycharm Image的 Python Packages

There search for selenium and install from there if not installed.如果未安装,则在那里搜索 selenium 并从那里安装。 Once installation is done rerun the script安装完成后重新运行脚本

If issue persist try to add chromedriver.exe file in C:\Python310\Scripts folder and check once如果问题仍然存在,请尝试在 C:\Python310\Scripts 文件夹中添加 chromedriver.exe 文件并检查一次

from selenium import webdriver

driver = webdriver.chrome.webdriver.WebDriver(executable_path='/Users/yatin/Downloads/chromedriver')

driver.get("http://www.python.org")
  • this worked perfectly fine in pycharm. Note: you must have already installed the selenium package from the interpreter这在 pycharm 中工作得很好。注意:您必须已经从解释器安装了 selenium package

and also match the current chrome version and chrome driver you are downloading, should be same version.并且还匹配当前的 chrome 版本和您正在下载的 chrome 驱动程序,应该是相同的版本。

though this command will work but this is depricated so here is new one:尽管此命令可以使用,但已被删除,因此这是新命令:

from selenium import webdriver

from selenium.webdriver.chrome.service import Service

service_obj = Service("/Users/yatin/Downloads/chromedriver")

driver = webdriver.chrome(service=service_obj)

driver.get("www.netflix.com")

I had the same problem and we solved it!!我有同样的问题,我们解决了!! I installed the newest version of python which is 3.9.我安装了最新版本的python 3.9。 I ran it and it yelled at me for selenium.我运行它,它对我大喊要硒。 So I went into command prompt and did :所以我进入命令提示符并做了:

pip install selenium

It installed selenium.它安装了硒。 I ran it, and it worked.我运行它,它工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AttributeError:模块&#39;selenium.webdriver&#39;没有属性&#39;Chrome&#39; - AttributeError: module 'selenium.webdriver' has no attribute 'Chrome' AttributeError: 模块“selenium.webdriver”没有属性“Chrome”错误,使用 ChromeDriver 和 Chrome 通过 Selenium - AttributeError: module 'selenium.webdriver' has no attribute 'Chrome' error using ChromeDriver and Chrome through Selenium AttributeError: 模块“selenium.webdriver”没有属性“webdriver” - AttributeError: module 'selenium.webdriver' has no attribute 'webdriver' AttributeError:模块“selenium.webdriver”没有属性“find_element” - AttributeError: module 'selenium.webdriver' has no attribute 'find_element' 模块“selenium.webdriver”没有属性“PhantomJS” - module 'selenium.webdriver' has no attribute 'PhantomJS' 模块“selenium.webdriver”没有属性“get” - module 'selenium.webdriver' has no attribute 'get' AttributeError:模块“selenium.webdriver”在 Selenium webdriver 中没有属性“w3c” - AttributeError: module 'selenium.webdriver' has no attribute 'w3c' in Selenium webdriver AttributeError: module 'selenium.webdriver.chrome.webdriver' has no attribute 'Chrome' 错误使用 Selenium ChromeDriver 和 Chrome - AttributeError: module 'selenium.webdriver.chrome.webdriver' has no attribute 'Chrome' error using Selenium ChromeDriver and Chrome Selenium错误消息“ selenium.webdriver没有属性执行脚本” - Selenium error message “selenium.webdriver has no attribute execute script” 没有名为“selenium.webdriver”的模块 - No module named 'selenium.webdriver'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM