我想通过 Selenium 无头启动 Firefox,但我似乎找不到这样做的方法并同时保持我的偏好。
from selenium import webdriver;
from selenium.webdriver import Firefox;
cProfile = webdriver.FirefoxProfile();
options = webdriver.FirefoxOptions();
dwnd_path = os.getcwd();
options.add_preference('browser.download.folderList', '2');
options.add_preference('browser.download.manager.showWhenStarting', 'false');
options.add_preference('browser.download.dir', 'dwnd_path');
options.add_preference('browser.helperApps.neverAsk.saveToDisk', 'application/octet-stream,application/vnd.ms-excel');
运行这个,我会得到这个错误:
Traceback (most recent call last):
File "test.py", line 17, in <module>
options.add_preference('browser.download.folderList', '2');
AttributeError: 'Options' object has no attribute 'add_preference'
有任何想法吗?