我已经尝试解决这个问题有一段时间了。
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:\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-测试的第二个解决方案是使用测试配置文件访问网站。
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/")执行代码后,将打开一个带有测试概要文件的新窗口,但它不起作用。
返回相同的错误:
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。提前谢谢。:)
发布于 2021-09-29 00:58:43
尝试下面的代码,看看它是否有帮助,因为当我从自己的角度尝试时,我看不到问题
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/")https://stackoverflow.com/questions/69369778
复制相似问题