首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >selenium.common.exceptions.InvalidArgumentException:

selenium.common.exceptions.InvalidArgumentException:
EN

Stack Overflow用户
提问于 2021-09-29 00:30:48
回答 1查看 84关注 0票数 0

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

代码语言:javascript
复制
from selenium import webdriver

driver = webdriver.Chrome(executable_path= r'./chromedriver.exe')

x= driver.get ("https://www.google.com/")

执行后,将打开一个带有url的选项卡:"data“

把这个还给我:

代码语言:javascript
复制
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-我测试的第一个解决方案是使用默认配置文件访问网站。

代码语言:javascript
复制
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = webdriver.ChromeOptions()
options.add_argument(r'--user-data-dir=C:\Users\Simone\AppData\Local\Google\Chrome\User Data\Profile 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-测试的第二个解决方案是使用测试配置文件访问网站。

代码语言:javascript
复制
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument(r"--user-data-dir=C:\Users\Simone\AppData\Local\Google\Chrome\User Data\Profile 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/")

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

返回相同的错误:

代码语言:javascript
复制
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。提前谢谢。:)

EN

回答 1

Stack Overflow用户

发布于 2021-09-29 00:58:43

尝试下面的代码,看看它是否有帮助,因为当我从自己的角度尝试时,我看不到问题

代码语言:javascript
复制
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/")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69369778

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档