Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python selenium webdriver在pycharm中给出错误_Python_Selenium_Selenium Webdriver_Pycharm_Selenium Chromedriver - Fatal编程技术网

Python selenium webdriver在pycharm中给出错误

Python selenium webdriver在pycharm中给出错误,python,selenium,selenium-webdriver,pycharm,selenium-chromedriver,Python,Selenium,Selenium Webdriver,Pycharm,Selenium Chromedriver,我在pycharm中对python3.7使用以下代码 from selenium import webdriver driver = webdriver.Chrome("C:\\chromedriver.exe") 但我有以下错误 File "C:/D/Project Documentation/Webdaq_504_Software/python_code/seleniumScripts/firstSeleniumsScript.py", line 3, in <module>

我在pycharm中对python3.7使用以下代码

from selenium import webdriver
driver = webdriver.Chrome("C:\\chromedriver.exe")
但我有以下错误

  File "C:/D/Project Documentation/Webdaq_504_Software/python_code/seleniumScripts/firstSeleniumsScript.py", line 3, in <module>
driver = webdriver.Chrome("C:\\chromedriver.exe")
AttributeError: module 'selenium.webdriver' has no attribute 'Chrome'
文件“C:/D/Project Documentation/Webdaq_504_Software/python_code/seleniumScripts/firstseleniumscript.py”,第3行,在
driver=webdriver.Chrome(“C:\\chromedriver.exe”)

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

但是,如果我在Pythonshell中逐行运行相同的代码,它就会正常工作。为什么我不能在pycharm中运行它。我尝试卸载并重新安装了所有内容。但什么都不管用

您需要添加可执行路径参数

driver = webdriver.Chrome(executable_path = "PATH_TO_WEBDRIVER")

您需要添加可执行路径参数

driver = webdriver.Chrome(executable_path = "PATH_TO_WEBDRIVER")

请记住,您应该在脚本的同一文件夹中设置,或者通过以下方式指定不同的路径:

driver = webdriver.Chrome(executable_path = "your/webdriver/path")
下面是一个非常简单的示例:

from selenium import webdriver

browser = webdriver.Chrome()
browser.get('https://www.google.com')
重要检查

  • 还要检查是否将脚本命名为webdriver.py或selenium.py。 这将导致依赖项出现问题,请确保使用其他名称重命名它
  • 不要将chromedriver.exe放在C:\中,这也会导致问题
更新

正如你所看到的:

确保Chrome/Google Chrome安装在可识别的位置
ChromeDriver希望您在平台的默认位置安装Chrome。您还可以强制ChromeDriver使用自定义位置。

请记住,您的脚本应该位于同一文件夹中,或者通过以下方式指定不同的路径:

driver = webdriver.Chrome(executable_path = "your/webdriver/path")
下面是一个非常简单的示例:

from selenium import webdriver

browser = webdriver.Chrome()
browser.get('https://www.google.com')
重要检查

  • 还要检查是否将脚本命名为webdriver.py或selenium.py。 这将导致依赖项出现问题,请确保使用其他名称重命名它
  • 不要将chromedriver.exe放在C:\中,这也会导致问题
更新

正如你所看到的:

确保Chrome/Google Chrome安装在可识别的位置 ChromeDriver希望您在平台的默认位置安装Chrome。您还可以强制ChromeDriver使用自定义位置。

尝试以下操作:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

browser = webdriver.Chrome(executable_path = r'C:/chromedriver_win32/chromedriver.exe')
browser.get("http://mail.google.com")
试试这个:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

browser = webdriver.Chrome(executable_path = r'C:/chromedriver_win32/chromedriver.exe')
browser.get("http://mail.google.com")


你用Py3.6试过了吗?有很多库尚未更新,在python shell中,键入“which python”,看看您是否真的在使用Py3.7。它是3.7,64位,请确保检查selenium是否与pip一起安装?pycharm没有使用selenium安装到的解释器。您使用Py3.6进行过尝试吗?有很多库尚未更新,在python shell中,键入“which python”,看看您是否确实在使用Py3.7。它是3.7,64位,请确保检查selenium是否与pip一起安装?pycharm没有使用selenium安装到intoSo的解释器,什么是exceptionAttributeError:module'selenium.webdriver'没有属性'Chrome',这是我收到的错误,它只发生在pycharm中,如果使用“python filename.py”从windows cmd运行脚本,它会工作right@Salman这可能是硒和铬版本之间不兼容的可能性。请将Selenium verison升级到3.13或3.12,那么,什么是exceptionAttributeError:模块'Selenium.webdriver'没有属性'Chrome',这是我收到的错误,它只在pycharm中发生,如果使用“python filename.py”从windows cmd运行脚本,它起作用了right@Salman这可能是硒和铬版本之间不兼容的可能性。请将Selenium verison升级到3.13或3.12,并将其移动到另一个文件夹而不是C,然后尝试与脚本相同的文件夹,但仍然存在相同的错误,而且脚本名称为“FirstSeleniumScript.py”@Salman请删除并重新安装Selenium:pip3安装--升级--强制重新安装selenium@Salman我的回答有用吗?如果是这种情况,请将其升级和/或选择它作为正确的一个移动到另一个文件夹而不是C,然后尝试与脚本相同的文件夹,但仍然存在相同的错误,并且脚本名称为“FirstSeleniumScript.py”,@Salman请删除并重新安装selenium:pip3安装--升级--强制重新安装selenium@Salman我的回答有用吗?如果是这种情况,请投票并/或选择正确的方案