javascript - Webdriver 在创建驱动程序时将书签添加到驱动程序,或将书签保存到书签 - 无需加载配置文件
问题描述
问题
我想将自定义小书签(纯 JavaScript 代码的书签)添加到 Web 驱动程序,以便它出现在书签工具栏中。这可以在创建时通过 add_extension 进行,也可以在页面加载后进行。
如何在没有用户交互且不加载配置文件的情况下将此小书签添加到 bookamrks 工具栏?欢迎任何想法
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_extension(r'C:\path\to\extension.crx')
# Have tried the below but doesn't open the add page to bookmarks?
"""actions = ActionChains(driver)
actions.send_keys(Keys.CONTROL + 'd')
actions.perform()
"""
解决方案
您可以在 selenium 中任意执行 javascript。您不需要书签即可执行此操作。看这个例子:
driver.execute_script("return true")
推荐阅读
- node.js - 无法通过在本地正常工作的nodejs服务器在heroku中部署角度项目
- typescript - 可选择调用的接口
- android - 实施 'com.android.support:appcompat-v7:28.0.0-alpha3'
- docker - RainLoop+tomav/docker-mailserver:无法从 RainLoop Webmail 客户端连接到服务器
- python - 保护 Flask API 中的图像路径
- java - 如何更改文档的版本?
- symfony - 如何通过IP自动改变环境
- asp.net-mvc - 即使从模型和控制器中删除,必填字段验证器仍会触发
- python - 如何找到总和为特定数字的所有数字对
- opencv - 获取错误:在 Ubuntu 16 上构建项目时找不到 -lopencv_dep_cudart