selenium.common.exceptions.InvalidArgumentException:



我已经尝试解决这个问题一段时间了。

from selenium import webdriver
driver = webdriver.Chrome(executable_path= r'./chromedriver.exe')
x= driver.get ("https://www.google.com/")

执行后会打开一个标签页,显示url: "data">

把这个返回给我:

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
到目前为止,这似乎是一个重复的问题,但它不是。在寻找解决方案时,我发现了两个不起作用的方法:

1-我测试的第一个解决方案是使用默认配置文件访问网站。

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = webdriver.ChromeOptions()
options.add_argument(r'--user-data-dir=C:UsersSimoneAppDataLocalGoogleChromeUser DataProfile 3')
options.add_argument(r'--profile-directory=Profile 3')
driver = webdriver.Chrome(executable_path=r'.chromedriver.exe', chrome_options=options)
driver.get("https://www.google.com/")

运行代码后,它实际上打开了一个新窗口,但它不访问网站。

返回相同的错误。

2 -测试的第二个解决方案是使用测试配置文件访问网站。

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument(r"--user-data-dir=C:UsersSimoneAppDataLocalGoogleChromeUser DataProfile 2")
options.add_argument(r'--profile-directory=Profile 2')
driver = webdriver.Chrome(executable_path=r'.chromedriver.exe', chrome_options=options)
driver.get("https://www.google.com/")

执行代码后,会打开一个带有测试概要文件的新窗口,但是它不起作用

返回相同的错误:

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
如果你能帮助我,我将非常感激,我正在学习python。提前感谢。:)

试试下面的代码,看看它是否有帮助,因为当我从我的一边尝试时,我没有看到一个问题

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
s=Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=s)
x= driver.get ("https://www.google.com/")

相关内容

最新更新