我用的是硒蟒。我的代码工作成功了,扩展被添加了。但是当我关闭代码时,打开Firefox配置文件,手动添加扩展,然后扩展就不会安装了。我的代码
从selenium导入time驱动程序从selenium.webdriver.common.by导入按导入时间
尝试:
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例外情况外:
print(E)
最后:
# exiting the fired Mozilla Firefox selenium webdriver instance
driver.quit()
# End Of Script
发布于 2022-08-07 11:35:49
当您要求Selenium使用一个概要文件时,它会将它复制到一个临时位置并使用此副本。所以不管你做什么都不会影响原始档案。
如果希望脚本影响原始配置文件,请不要要求Selenium使用概要文件。相反,直接告诉Firefox要使用哪个配置文件:
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)
https://stackoverflow.com/questions/72883543
复制相似问题