<i id='LHG7O'><tr id='LHG7O'><dt id='LHG7O'><q id='LHG7O'><span id='LHG7O'><b id='LHG7O'><form id='LHG7O'><ins id='LHG7O'></ins><ul id='LHG7O'></ul><sub id='LHG7O'></sub></form><legend id='LHG7O'></legend><bdo id='LHG7O'><pre id='LHG7O'><center id='LHG7O'></center></pre></bdo></b><th id='LHG7O'></th></span></q></dt></tr></i><div id='LHG7O'><tfoot id='LHG7O'></tfoot><dl id='LHG7O'><fieldset id='LHG7O'></fieldset></dl></div>
  • <tfoot id='LHG7O'></tfoot>
      • <bdo id='LHG7O'></bdo><ul id='LHG7O'></ul>

      <small id='LHG7O'></small><noframes id='LHG7O'>

        <legend id='LHG7O'><style id='LHG7O'><dir id='LHG7O'><q id='LHG7O'></q></dir></style></legend>

        InvalidArgumentException:消息:无效参数:使用 ChromeDriver Selenium 启动

        InvalidArgumentException: Message: invalid argument: user data directory is already in use error while initiating Chrome with ChromeDriver Selenium(InvalidArgumentException:消息:无效参数:使用 ChromeDriver Selenium 启动 Chrome 时,用户数据目
      1. <small id='ZWgYj'></small><noframes id='ZWgYj'>

        <legend id='ZWgYj'><style id='ZWgYj'><dir id='ZWgYj'><q id='ZWgYj'></q></dir></style></legend>
          <bdo id='ZWgYj'></bdo><ul id='ZWgYj'></ul>
              <tfoot id='ZWgYj'></tfoot>
              <i id='ZWgYj'><tr id='ZWgYj'><dt id='ZWgYj'><q id='ZWgYj'><span id='ZWgYj'><b id='ZWgYj'><form id='ZWgYj'><ins id='ZWgYj'></ins><ul id='ZWgYj'></ul><sub id='ZWgYj'></sub></form><legend id='ZWgYj'></legend><bdo id='ZWgYj'><pre id='ZWgYj'><center id='ZWgYj'></center></pre></bdo></b><th id='ZWgYj'></th></span></q></dt></tr></i><div id='ZWgYj'><tfoot id='ZWgYj'></tfoot><dl id='ZWgYj'><fieldset id='ZWgYj'></fieldset></dl></div>

                  <tbody id='ZWgYj'></tbody>
                1. 本文介绍了InvalidArgumentException:消息:无效参数:使用 ChromeDriver Selenium 启动 Chrome 时,用户数据目录已在使用中出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用我的默认用户使用 selenium python 库打开一个网页,脚本使用默认用户很重要,但如果我的 chrome 浏览器已经打开,脚本会崩溃并给我这个错误:

                  selenium.common.exceptions.InvalidArgumentException:消息:无效参数:用户数据目录已在使用中,请为 --user-data-dir 参数指定唯一值,或者不要使用 --user-数据目录

                  我已经尝试了这里给出的所有解决方案:

                  现有 Chrome 浏览器会话中的新窗口快照:

                  <小时>

                  结论

                  虽然错误仍然被抛出,但新的 Chrome 窗口仍会启动,但仍与已打开的 Chrome 会话连接,但新窗口无法由 WebDriver 实例.

                  <小时>

                  解决方案

                  你需要注意几件事:

                  • 如果您使用 默认 Chrome 配置文件在同一台测试机上访问其他工作的网页,则不应设置 user-data-dir 作为用户数据,因为它仍然被您手动启动的其他 Chrome 进程锁定.
                    • 在上述场景中,您需要创建和使用另一个 Chrome 配置文件,您可以在 如何通过 Python 打开 Chrome 配置文件
                  • 如果你在一个独立的测试系统中执行你的测试,你可以将user-data-dir设置为..User DataDefault 以访问默认 Chrome 配置文件.
                    • 在上述场景中,您需要创建和使用另一个 Chrome 配置文件,您可以在 如何在 Selenium Webdriver Python 3 中使用 Chrome 配置文件
                  • 但是,根据最佳做法,您必须始终创建一个新的 Chrome 配置文件来执行您的测试,因为 默认 Chrome 配置文件可能包含 扩展程序书签浏览历史等,可能无法正常加载.
                    • 您可以在 如何通过 Selenium 的 --user-data-dir 参数打开 Chrome 配置文件

                  I am trying to open a web page using the selenium python library with my default user, it is critical that the script uses the default user but if my chrome browser is already open the script crashes and gives me this error:

                  selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir
                  

                  I have tried all the solutions given here :

                  Selenium chromedriver won't launch URL if another chrome instance is open

                  Selenium won't open a new URL in a new tab (Python & Chrome)

                  and read that there was a bug in older chromedriver versions but it was fixed in chrome 74 (which im using ) : https://github.com/SeleniumHQ/docker-selenium/issues/741

                  from selenium import webdriver
                  import time
                  from getpass import getuser
                  
                  def run():
                      # Chrome driver path
                      chromedriver = r'C:Usersuser1Downloadschromedriver_win32chromedriver_new.exe'
                  
                      # Get chrome webdriver options and set open the browser as headless
                      chrome_options = webdriver.ChromeOptions()
                      #chrome_options.add_argument("--headless")
                  
                      # Fix for selenium Issue 2907
                      #chrome_options.add_argument('--log-level=3')
                      #chrome_options.add_experimental_option('excludeSwitches', ['enable-logging'])
                  
                      # Load current user default profile
                      current_user = getuser()
                      chrome_options.add_argument(
                          r"--user-data-dir=C:Users{}AppDataLocalGoogleChromeUser Data".format(current_user))
                  
                      # didable "Chrome is being controled by an automated test software"
                      chrome_options.add_argument('disable-infobars')
                  
                      # get Chrome to stay open
                      chrome_options.add_experimental_option("detach", True)
                  
                      # open browser with options and driver
                      driver = webdriver.Chrome(options=chrome_options, executable_path=chromedriver)
                      driver.get(r'https://www.youtube.com/watch?v=dQw4w9WgXcQ')
                  
                  
                  
                  if __name__ == '__main__':
                      run()
                  

                  if i run it without a chrome browser open its fine if not it crashes

                  解决方案

                  This error message...

                  selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir
                  

                  ...implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session using the specified user data directory as it was already in use.


                  I was able to reproduce the error in my local windows-10box as follows:

                  • Code Block:

                    from selenium import webdriver
                    import getpass
                    
                    options = webdriver.ChromeOptions() 
                    options.add_argument("start-maximized")
                    options.add_argument(r"--user-data-dir=C:Users{}AppDataLocalGoogleChromeUser Data".format(getpass.getuser()))
                    driver = webdriver.Chrome(options=options, executable_path=r'C:WebDriverschromedriver.exe')
                    driver.get("https://www.google.com/")
                    

                  • Complete relevant traceback:

                    [18516:23156:0204/032227.883:ERROR:cache_util_win.cc(21)] Unable to move the cache: Access is denied. (0x5)
                    [18516:23156:0204/032227.898:ERROR:cache_util.cc(141)] Unable to move cache folder C:UsersSoma BhattacharjeeAppDataLocalGoogleChromeUser DataShaderCacheGPUCache to C:UsersSoma BhattacharjeeAppDataLocalGoogleChromeUser DataShaderCacheold_GPUCache_000
                    [18516:23156:0204/032227.898:ERROR:disk_cache.cc(178)] Unable to create cache
                    [18516:23156:0204/032227.898:ERROR:shader_disk_cache.cc(605)] Shader Cache Creation failed: -2
                    Opening in existing browser session.
                    Traceback (most recent call last):
                    .
                    selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir
                    


                  Analysis

                  The error stack trace clearly complains of Access is denied as the program was unable to move the cache folder ..ShaderCacheGPUCache to ..ShaderCacheold_GPUCache_000. hence the creation of cache failed and subsequently creation of Shader Cache Creation failed. Though these issues raises the InvalidArgumentException but forcefully able to open a new window within the existing Chrome Browser Session.

                  Snapshot of existing Chrome Browser Session:

                  Snapshot of new window within the existing Chrome Browser Session:


                  Conclusion

                  Though the error is thrown still the new Chrome window gets initiated but remains attached with the already opened Chrome session but the new window can't be controlled by the WebDriver instance.


                  Solution

                  You need to take care of a couple of things:

                  • If you are using the Default Chrome Profile to access webpages for your other work on the same Test Machine, you shouldn't set user-data-dir as the User Data as it remains locked by the other Chrome process you have initiated manually.
                    • In the above scenario you need to create and use another Chrome Profile and you can find a detailed discussion in How to open a Chrome Profile through Python
                  • If you are executing your tests in a isolated test system, you can set user-data-dir as ..User DataDefault to access the Default Chrome Profile.
                    • In the above scenario you need to create and use another Chrome Profile and you can find a detailed discussion in How to use Chrome Profile in Selenium Webdriver Python 3
                  • However as per best practices you must always create a new Chrome Profile to execute your tests as the Default Chrome Profile may contain Extensions, Bookmarks, Browsing History, etc, and may not load properly.
                    • You can find a detailed discussion in How to open a Chrome Profile through --user-data-dir argument of Selenium

                  这篇关于InvalidArgumentException:消息:无效参数:使用 ChromeDriver Selenium 启动 Chrome 时,用户数据目录已在使用中出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Kivy 1.9.0 Windows package KeyError: #39;rthooks#39;(Kivy 1.9.0 Windows 包 KeyError: rthooks)
                  Python Kivy: how to call a function on button click?(Python Kivy:如何在按钮单击时调用函数?)
                  How to disable a widget in Kivy?(如何禁用 Kivy 中的小部件?)
                  Centering an object in Kivy(在 Kivy 中将对象居中)
                  How to downgrade to Python 3.4 from 3.5(如何从 Python 3.5 降级到 Python 3.4)
                  Change button or label text color in kivy(在kivy中更改按钮或标签文本颜色)

                  <small id='1yPs5'></small><noframes id='1yPs5'>

                  <legend id='1yPs5'><style id='1yPs5'><dir id='1yPs5'><q id='1yPs5'></q></dir></style></legend>

                    <i id='1yPs5'><tr id='1yPs5'><dt id='1yPs5'><q id='1yPs5'><span id='1yPs5'><b id='1yPs5'><form id='1yPs5'><ins id='1yPs5'></ins><ul id='1yPs5'></ul><sub id='1yPs5'></sub></form><legend id='1yPs5'></legend><bdo id='1yPs5'><pre id='1yPs5'><center id='1yPs5'></center></pre></bdo></b><th id='1yPs5'></th></span></q></dt></tr></i><div id='1yPs5'><tfoot id='1yPs5'></tfoot><dl id='1yPs5'><fieldset id='1yPs5'></fieldset></dl></div>
                    <tfoot id='1yPs5'></tfoot>
                      <tbody id='1yPs5'></tbody>
                        <bdo id='1yPs5'></bdo><ul id='1yPs5'></ul>