生成浏览器插件扩展程序,在启动driver时加载插件
extension_path 插件路径 driver.install_addon(path=extension_path,temporary=True)#添加扩展 fixfox chrome_options.add_extension(extension_path) #Chrome添加扩展
#注意 插件文件是一个.zip的压缩包
injected.js#文件名称 ################文件内容 Element.prototype._attachShadow = Element.prototype.attachShadow; Element.prototype.attachShadow = function () { console.log('attachShadow'); return this._attachShadow( { mode: "open" } ); };
manifest.json#文件名称 ##############文件内容 { “name”: “SeleniumTesting”, “description”: “网页上的shadow-root(closed)重载成shadow-root(open),变成可操作状态”, “version”: “1.0”, “author”: “Author”, “manifest_version”: 2, “permissions”: ["<all_urls>"], “content_scripts”: [{ “matches”: ["https://xxxxxx(生效网站).com/”], “run_at”: “document_start”, “all_frames”: true, “js”: [“shadowInject.js”] },
"icons": {"48": "icons/border-48.png"}#一个文件夹,插件图标
], “web_accessible_resources”: [“injected.js”] }
shadowInject.js #文件名称 ###文件内容 const injectedScript = document.createElement('script'); injectedScript.src = chrome.extension.getURL('injected.js'); (document.head || document.documentElement).appendChild(injectedScript);
标签:插件,extension,js,closed,attachShadow,path,shadow,root From: https://www.cnblogs.com/buchi-baicai/p/18243482