带有Firefor或Chrome配置文件的硒 [英] Selenium with Firefor or Chrome profile
问题描述
我正在尝试将配置文件加载到selenium,这样我就不必继续登录到selenium即将访问的网站.我在Mac上使用python运行它.
在Firefox版本中,我使用以下代码
def create_selenium_FF():配置文件= webdriver.FirefoxProfile('/Users/Victor/Library/Application Support/Firefox/Profiles/z3ay0enb.default')driver = webdriver.Firefox(配置文件)回程司机
它可以成功启动firefox,但是它没有所访问网站的登录信息,但是我使用about:profiles签入了自动firefox浏览器,它确实可以识别我提供的配置文件./p>
在chrome版本中,我使用以下代码,请注意,我已经在本地创建了个人资料副本.
def create_selenium_chrome():DRIVER ='chromedriver'选项= webdriver.ChromeOptions()options.add_argument(-user-data-dir =/Users/Victor/Library/Application Support/Google/Chrome2")options.add_argument(-profile-directory =默认")driver = webdriver.Chrome(DRIVER,options = options)回程司机
它也可以启动chrome,看起来像我的个人资料一样,但是会引发错误
selenium.common.exceptions.InvalidArgumentException:消息:无效参数:用户数据目录已在使用中,请为--user-data-dir参数指定唯一值,或者不使用--user-数据目录
请问如何使它正常工作?
我刚刚解决了这个问题!
这是我的代码:
从硒导入Webdriver的 选项= webdriver.ChromeOptions()options.add_argument("user-data-dir = C:\\ Users \\%username%\\ AppData \\ Local \\ Google \\ Chrome \\ User Data 2")驱动程序= webdriver.Chrome(executable_path =路径,选项=选项)driver.get(" https://www.google.com")
问题是,如果您的计算机上已打开Chrome,则会出现此错误!
所以,我只复制/粘贴文件夹用户数据",然后将粘贴的文件夹重命名为用户数据2",以便我的Chrome浏览器可以处理用户数据,而硒可以处理用户数据2.
我知道你已经等了很久了,我不知道你是否仍然需要这个,但是你在这里!!
I am trying to load a profile to selenium so that I dont have to keep log in to the website that selenium is about to visit. I am running it with python on my Mac.
In the firefox version, I use the below code
def create_selenium_FF():
profile = webdriver.FirefoxProfile('/Users/Victor/Library/Application Support/Firefox/Profiles/z3ay0enb.default')
driver = webdriver.Firefox(profile)
return driver
It can successfully start firefox, but it doesn't have the log in info of the website that it visits, however I check in the automated firefox browser using about:profiles, it does recognise the profile that I feed it.
in the chrome version, I use the below code, notice I make a local copy of the profile already.
def create_selenium_chrome():
DRIVER = 'chromedriver'
options = webdriver.ChromeOptions()
options.add_argument("--user-data-dir=/Users/Victor/Library/Application Support/Google/Chrome2")
options.add_argument("--profile-directory=Default")
driver = webdriver.Chrome(DRIVER, options=options)
return driver
it can also start chrome, and looks like it has my profile, but it raises an 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
How can I get it working please?
I just solved the problem !
So here is my code :
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Users\\%username%\\AppData\\Local\\Google\\Chrome\\User Data 2")
driver = webdriver.Chrome(executable_path=path,options=options)
driver.get("https://www.google.com")
The thing is, you'll get this error if there already is chrome opened on your computer !
So, i just copy / paste the folder User Data and rename the pasted one into User Data 2 so my chrome works with user data and selenium with user data 2 I guess.
I know that you've been waiting for a long time and I don't know if u still need this but here you got !!
这篇关于带有Firefor或Chrome配置文件的硒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!