首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >通过selenium firefox配置文件成功添加扩展。但是当我手动打开这些Firefox时,这个扩展仍然没有安装

通过selenium firefox配置文件成功添加扩展。但是当我手动打开这些Firefox时,这个扩展仍然没有安装
EN

Stack Overflow用户
提问于 2022-07-06 12:26:12
回答 1查看 67关注 0票数 0

我用的是硒蟒。我的代码工作成功了,扩展被添加了。但是当我关闭代码时,打开Firefox配置文件,手动添加扩展,然后扩展就不会安装了。我的代码

从selenium导入time驱动程序从selenium.webdriver.common.by导入按导入时间

尝试:

代码语言:javascript
运行
复制
path = "My_profile_PATH"
fp = webdriver.FirefoxProfile(path)     
driver = webdriver.Firefox(firefox_profile=fp)

# path to your downloaded Firefox addon extension XPI file

extension_path = "MY_extension_PATH"

# using webdriver's install_addon API to install the downloaded Firefox extension

driver.install_addon(extension_path, temporary=True)

# Opening the Firefox support page to verify that addon is installed

driver.get("about:support")

# xpath to the section on the support page that lists installed extension

addons = driver.find_element(By.XPATH,'//*[contains(text(),"Add-ons") and not(contains(text(),"with"))]')
# scrolling to the section on the support page that lists installed extension

driver.execute_script("arguments[0].scrollIntoView();", addons)

# introducing program halt time to view things, ideally remove this when performing test automation in the cloud using LambdaTest

print("Success. Yayy!!")

time.sleep(20)

除E例外情况外:

代码语言:javascript
运行
复制
print(E)

最后:

代码语言:javascript
运行
复制
# exiting the fired Mozilla Firefox selenium webdriver instance

driver.quit()

# End Of Script
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-07 11:35:49

当您要求Selenium使用一个概要文件时,它会将它复制到一个临时位置并使用此副本。所以不管你做什么都不会影响原始档案。

如果希望脚本影响原始配置文件,请不要要求Selenium使用概要文件。相反,直接告诉Firefox要使用哪个配置文件:

代码语言:javascript
运行
复制
from selenium import webdriver
from selenium.webdriver.firefox.options import Options

options = Options()
options.add_argument('-profile')
options.add_argument('/path/to/your/profile')

driver = webdriver.Firefox(options=options)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72883543

复制
相关文章

相似问题

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