我刚刚使用 Python 启动了 Selenium。我正面临属性错误问题。
已安装 Python 3.6.5 并安装最新的 selenium 包(selenium-3.11.0)
还在环境变量中添加了脚本和 Python 文件夹路径: PATH 。
下载 chromedriver.exe 并将相应的文件路径添加到环境变量中。
但是在运行以下代码时:
from selenium import webdriver
driver = webdriver.Chrome("E:\Selenium\chromedriver_win32\chromedriver.exe")
它抛出以下错误:
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
尝试了 Stack Overflow 中提供的所有其他解决方案,例如卸载和重新安装 Python 以及升级 selenium。但没有任何帮助。
代码是使用 PyCharm IDE 运行的,但是当使用 IDLE 运行时它工作正常。
可以在 Sitepackages -> selenium -> webdriver 下找到 firefox、chrome、safari、phantomjs、android 等文件夹。但不确定为什么它仍然显示“Webdriver has no attribute chrome”
附上上面的截图。在 webdriver 下显示没有模块 chrome()
任何帮助,将不胜感激。
原文由 Stk 发布,翻译遵循 CC BY-SA 4.0 许可协议
这是编写该代码的正确方法,如果你想使用 firefox 或其他东西,那么将 chrome 更改为 firefox …还阅读第一个文档并查找一些示例,如果你什么也没找到,请将其放在这里
也可以使用 pip install selenium !