Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.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 3.x Selenium启动了一个Chrome会话,但之后立即崩溃_Python 3.x_Selenium_Google Chrome_Selenium Webdriver_Selenium Chromedriver - Fatal编程技术网

Python 3.x Selenium启动了一个Chrome会话,但之后立即崩溃

Python 3.x Selenium启动了一个Chrome会话,但之后立即崩溃,python-3.x,selenium,google-chrome,selenium-webdriver,selenium-chromedriver,Python 3.x,Selenium,Google Chrome,Selenium Webdriver,Selenium Chromedriver,我在尝试打开会话时收到其中一个错误 selenium.common.exceptions.SessionNotCreateException:消息:未创建会话 无法从chrome访问 (会话信息:chrome=80.0.3987.132) selenium.common.exceptions.SessionNotCreateException:消息:未创建会话 来自断开连接:无法从渲染器接收消息 (会话信息:chrome=80.0.3987.132) 色度驱动器=80.0.3987.106 我在

我在尝试打开会话时收到其中一个错误

selenium.common.exceptions.SessionNotCreateException:消息:未创建会话 无法从chrome访问 (会话信息:chrome=80.0.3987.132)

selenium.common.exceptions.SessionNotCreateException:消息:未创建会话 来自断开连接:无法从渲染器接收消息 (会话信息:chrome=80.0.3987.132)

色度驱动器=80.0.3987.106

我在谷歌上搜索了这些错误,没有一个解决方案有用,这是我当前的代码:(其中一个解决方案建议添加Chrome选项)

从selenium导入webdriver
类YoutubeBot():
定义初始化(自):
chrome\u options=webdriver.ChromeOptions()
chrome_选项。添加_参数('--no sandbox')
self.driver=webdriver.Chrome('/usr/local/bin/chromedriver',Chrome\u options=Chrome\u options)
编辑:我现在发现这个问题是通过使用headless解决的,我仍然希望在编写代码时测试我的代码,可能还有其他解决方案吗?(我正在Arch Linux上使用Xfce4 DE)

此错误消息

selenium.common.exceptions.SessionNotCreatedException: Message: session not created from disconnected: Unable to receive message from renderer (Session info: chrome=80.0.3987.132)
…表示ChromeDriver无法启动/生成新的Chrome浏览器会话


你需要考虑两件事:

  • ChromeDriver的绝对位置必须通过键/值对传递,如下所示:

    driver = webdriver.Chrome(executable_path='/Users/qa/Documents/Python/chromedriver')
    
  • 初始化会话时,您需要使用
    选项
    参数,而不是
    chrome\u选项

  • 因此,有效地,您的代码块将是:

    from selenium import webdriver
    
    class YoutubeBot():
        def __init__(self):
            chrome_options = webdriver.ChromeOptions()
            chrome_options.add_argument('--no-sandbox')
            self.driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver', options=chrome_options)
    

    • 解决方案很简单,
      sudo
      文件。 我觉得自己很愚蠢,应该早点检查一下,也许应该考虑一下。
      运行时,我所要做的就是
      sudo python-I main.py
      和Chrome神奇地启动,没有错误。

      您是在没有桌面的计算机上运行这个吗?您可能需要在无头模式下运行Chrome。@GregBurghardt我有一个桌面环境,Chrome窗口会弹出一两秒钟,但没有显示任何有用的内容,然后由于一个错误而崩溃。@GregBurghardt update:看起来它在无头模式下没有崩溃,这很奇怪。这肯定很奇怪。我有默认路径,所以这两种方式都不重要,尽管如此,我尝试了你的解决方案,但我得到了相同的错误。你的用户是否拥有Chrome和ChromeDriver的读取和执行权限?通常,
      sudo
      就像用大锤敲击大头钉一样。我会担心Chrome和ChromeDriver作为
      root
      运行。。。除非我是个黑客。然后我会非常喜欢它。:-)@GregBurghardt我拥有Chrome和ChromeDriver的读、写、执行权限。也许我对Selenium包或Python没有这些权限?