栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Python / Selenium / Firefox:无法使用指定的配置文件路径启动Firefox

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python / Selenium / Firefox:无法使用指定的配置文件路径启动Firefox

我花了大约2个小时(是的,我太慢了)猜测为什么不起作用。我发现了为什么个人资料不保存回去。

当然,传递给

FirefoxProfile("myprofile/full/path")
它的配置文件是在运行时使用的,但是它并没有保存回去,因为(也许不是很明显)硒用于测试,并且测试应该在没有缓存,没有任何配置文件,尽可能干净的情况下运行。

配置文件功能(可能)是为了允许在运行测试之前安装某些扩展名和设置而创建的,而不是为了保存它们。

诀窍是打印出来

print driver.firefox_profile.path
。它与通常的确有所不同,其名称为 tmp / tmpOEs2RR /
webdriver-py-profilecopy,而
不仅仅是 tmp / tmpOEs2RR / ,因此请阅读您应该猜测的配置文件。

现在,剩下的唯一事情就是找回它:)

运行此脚本,安装内容,编辑内容,然后再次运行;):

#!/usr/bin/env python#! -*- coding: utf-8 -*-import seleniumfrom selenium import webdriverimport os, sys, time# 1- set profileprofile = os.path.dirname(sys.argv[0]) + "/selenita"fp = webdriver.FirefoxProfile(profile)driver = webdriver.Firefox(firefox_profile=fp)# 2- get tmp file locationprofiletmp = driver.firefox_profile.path# but... the current profile is a copy of the original profile :/print "running profile " + profiletmpdriver.get("http://httpbin.org")time.sleep(2)raw_input("Press a key when finish doing things") # I've installed an extension# 3- then save backprint "saving profile " + profiletmp + " to " + profileif os.system("cp -R " + profiletmp + "/* " + profile ):    print "files should be copied :/"driver.quit()sys.exit(0)

您可以遵循该架构,也可以根据需要简单地编辑FirefoxProfilea。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/387437.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号